Reputation: 3155
I've a website at http://ex.com/web2/
this is a real path in my server, but I wanted visitors to be able to access the website also over the URL http://ex.com/web3/
(without changing the URL on the browser), so after looking around (and asking help) I added the following to my .htaccess
:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^web3/?$ /web2/ [L,NC]
RewriteRule ^web3/(.+)$ /web2/$1 [L,NC]
</IfModule>
The "silent" redirect that DOES NOT change the browser URL works fine, but in PHP if I print $_SERVER[REQUEST_URI]
I get the URL the user placed on the browser, /web3/
instead of /web2/
.
Is there any way .htaccess
can also "fake" the path that is sent to the PHP var?
(I was told this would be hard or even impossible.)
Thank you.
Upvotes: 0
Views: 4728
Reputation: 143856
If you have mod_proxy loaded, you could internally proxy the request. That will change the REQUEST_URI
server variable, but it's sort of a round about way to do it. Would be far more efficient if it all happened in the php scripts.
RewriteRule ^web3/?$ /web2/ [L,NC,P]
RewriteRule ^web3/(.+)$ /web2/$1 [L,NC,P]
Just need to add the P
flag to the square brackets.
Upvotes: 2