I have an issue with Apache passing to the PHP $_SERVER['REQUEST_URI']
variable the URL after it has been rewritten rather than the original one requested.
I am doing this rewriting because I had a WordPress website and wanted to move it to a subdirectory rather than having it in a root path, but still wanted to keep its URL to be the root URL.
This does not happen consistently. If I request www.xyz.com/wp-admin
it populates the PHP REQUEST_URI
variable with www.xyz.com/wordpress/wp-admin
(which is the URL after it has been rewritten), but if I request www.xyz.com/wp-admin/
(with a trailing slash) it actually populates the PHP REQUEST_URI
variable with www.xyz.com/wp-admin/
(the original URL, before the rewriting). What I want is for the REQUEST_URI
to be populated with the URL before it has been rewritten.
My .htaccess
file is below:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?xyz.com$
RewriteCond %{REQUEST_URI} !^/wordpress/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wordpress/$1
RewriteCond %{HTTP_HOST} ^(www.)?xyz.com$
RewriteRule ^(/)?$ wordpress/index.php [L]
</IfModule>`
PHP version is 5.3. Apache version is 2.4 (Win32).
UPDATE: I looked into it more and when I type in the URL www.xyz.com/wp-admin
then there is a 301 redirect first to www.xyz.com/wordpress/wp-admin/
but this does not happen for www.xyz.com/wp-admin/
(with a trailing slash). For the one with the trailing slash there is only the rewrite, as expected.
So the question now is why the 301 redirect happens in the first place for the URL without the trailing slash.
To clarify, there is no actual folder /wp-admin/
, but there is a folder /wordpress/wp-admin/
.