.htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^cars/(.*).html$ /control.php [P,L]
RewriteRule ^trucks/(.*).html$ /control.php [P,L]
/control.php
<pre>
<?php
echo "Path Requested: " . $_SERVER['REQUEST_URI'] . "\n\n";
print_r($_SERVER);
?>
</pre>
Test URL (real hostname replaced with "example.com")
http://example.com/trucks/valugatah.html
Result
Path Requested: /control.php
Array
(
[CONTEXT_DOCUMENT_ROOT] => /home/fubelboobin/public_html
[CONTEXT_PREFIX] =>
[DOCUMENT_ROOT] => /home/fubelboobin/public_html
[GATEWAY_INTERFACE] => CGI/1.1
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
[HTTP_ACCEPT_ENCODING] => gzip, deflate
[HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.8,gl;q=0.6
[HTTP_CACHE_CONTROL] => max-age=0
[HTTP_CONNECTION] => close
[HTTP_HOST] => fubelboobin.com
[HTTP_UPGRADE_INSECURE_REQUESTS] => 1
[HTTP_USER_AGENT] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
[HTTP_X_FORWARDED_FOR] => 23.241.124.74
[HTTP_X_FORWARDED_HOST] => fubelboobin.com
[HTTP_X_FORWARDED_SERVER] => fubelboobin.com
[PATH] => /bin:/usr/bin
[QUERY_STRING] =>
[REDIRECT_STATUS] => 200
[REMOTE_ADDR] => 166.62.119.108
[REMOTE_PORT] => 47854
[REQUEST_METHOD] => GET
[REQUEST_SCHEME] => http
[REQUEST_URI] => /control.php
[SCRIPT_FILENAME] => /home/fubelboobin/public_html/control.php
[SCRIPT_NAME] => /control.php
[SERVER_ADDR] => 166.62.119.108
[SERVER_ADMIN] => webmaster@fubelboobin.com
[SERVER_NAME] => fubelboobin.com
[SERVER_PORT] => 80
[SERVER_PROTOCOL] => HTTP/1.1
[SERVER_SIGNATURE] =>
[SERVER_SOFTWARE] => Apache
[UNIQUE_ID] => WfUhgaY@d2wAACMqjNMAAAAF
[PHP_SELF] => /control.php
[REQUEST_TIME_FLOAT] => 1509237121.06
[REQUEST_TIME] => 1509237121
[argv] => Array
(
)
[argc] => 0
)
Note that the url visible inside the browser address bar is (as expected and desired):
http://example.com/trucks/valugatah.html
So what's the problem?
I am expecting the $_SERVER['REQUEST_URI']
to be the same as what I see in the address bar, which is the original url of /trucks/valugatah.html
however, as you can see from my posted Result $_SERVER['REQUEST_URI']
is returning /control.php
This shouldn't be a problem, because according to the docs, if $_SERVER['REQUEST_URI']
gets overwritten, then I should have access to a new var (automatically created) named $_SERVER['REDIRECT_REQUEST_URI']
that preserves the original $_SERVER['REQUEST_URI']
but as you can see from my Result, $_SERVER['REDIRECT_REQUEST_URI']
never gets created.
I've read everything I could find over the last 2 days, and I've got nothing...
Removing the "P" flags from inside the .htaccess file solved it. Here's the working code:
.htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^cars/(.*).html$ /control.php [L]
RewriteRule ^trucks/(.*).html$ /control.php [L]