Reputation: 2072
My webroot is example.com
. I have two sub-directories below webroot, named sub1
and sub2
. Inside sub1
I've placed the following .htaccess
:
RewriteEngine On
RewriteCond %{REQUEST_URI} test\.me$ [NC]
#RewriteRule ^(.*)$ http://example.com/sub2/foo.html [L]
RewriteRule ^(.*)$ /sub2/foo.html [L]
When someone tries to access http://example.com/sub1/test.me
, I want them to be served http://example.com/sub2/foo.html
.
The above .htaccess
does not work. If I un-comment the RewriteRule with the full path, and comment out the RewriteRule with the path relative to the webroot, it almost works as intended (the right page is shown, but the URL shown is also changed from http://example.com/sub1/test.me
to http://example.com/sub2/foo.html
, which is not wanted).
I am not able to understand why the full path almost works, while the path relative to the siteroot don't.
And if anyone could explain why my approach don't work, and what the the "best practice" for doing this type of redirection is - I would be grateful.
Upvotes: 0
Views: 90
Reputation: 2072
I've solved it.
Unfortunately, I oversimplified the setting when I composed the question. In fact, in a "virgin" environment the original .htaccess
works exactly as I intended it to work.
However, the setting I'm using this .htaccess
is with Drupal 7, and this makes a difference, since Drupal 7 uses "clean URLs".
What I found is that rewriting to a "clean" url do not work. So the following rule in .htaccess
do not work when redirecting to Drupal node #1:
RewriteRule ^(.*)$ /sub2/node/1
However, the following does:
RewriteRule ^(.*)$ /sub2/?q=node/1
Apologies for not putting all that was relevant for cracking it in the question.
I hope this answer helps someone that struggles with the same thing.
Upvotes: 1