Initially, this code was written to create “pretty” urls.
When using the code below, mod_rewrite works as it should.
<Directory /var/www/vhosts/myurl.com/httpdocs>
Options Indexes FollowSymLinks
php_admin_flag engine on
php_admin_value open_basedir none
AllowOverride all
Order allow,deny
Allow from all
</Directory>
RewriteEngine on
RewriteCond %{HTTPS} !=off
RewriteCond %{LA-U:REQUEST_FILENAME} !-f
RewriteCond %{LA-U:REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond $1 ^(register|account|logout|profile|edit_profile).*$
RewriteRule ^/(.*)$ https://myurl.com/?get=$1
It takes any matching url such as https://myurl.com/register and rewrites it as https://myurl.com/?get=register. The appropriate page is found and displayed in the browser.
However, I want the original url to be passed through to the browser. To achieve this, I added the [PT] Flag to my RewriteRule as shown below:
RewriteRule ^/(.*)$ https://myurl.com/?get=$1 [PT]
This lets https://myurl.com/register (same url as above) through to the browser but no longer displays the page. Instead, it returns the following error:
Bad Request
Your browser sent a request that this server could not understand.
Client sent malformed Host header
Relevant Info:
OS: Linux
Server: Apache
Control: Plesk
Directory: /var/www/vhosts/myurl.com/conf
File: vhost_ssl.conf
I’ve searched multiple forums and articles to no avail.
Article 1: Making prettier URLs with mod_rewrite (includes use of [PT] Flag)
Does anyone have ideas on what’s going on here and how to fix it? How can I get the “pretty” url to display?
So after two days of frustration, I finally solved the puzzle.
First I experimented with the RewriteRule from by changing it from:
to
without any flags.
This produced an infinite loop whenever the rewrite was triggered. But I noticed that the loop was happening without redirecting the url (maintaining the ‘pretty url’). Progress!
I decided to simplify the code. I removed ‘LA-U:’ from the RewriteCond as shown below:
to
That did the trick! Thanks to those that commented. Hope this helps someone in the future.