Forum Moderators: phranque
[olddomain.com...]
but if I go to this url:
[olddomain.com...]
then it doesn't redirect. So here's my code, which resides in
[olddomain.com...]
:
RewriteEngine On
RewriteRule /directory/index.php [newdomain.com...] [R=301,NC,L] #note that this line was just a prayer that didn't work :)#
RewriteRule /directory [newdomain.com...] [R=301,NC,L]
ErrorDocument 404 [newdomain.com...]I had also tried this in the past and it didn't work:
RewriteRule /directory/ [newdomain.com...] [R=301,NC,L]
1) The URL-paths tested by the RewriteRule pattern in .htaccess are stripped of their leading slash, because .htaccess operates in a per-directory context. Therefore, the directory-level part of the URL - the slash - is removed. And therefore, your pattern, in which you specify a leading slash, would never match.
2) If you use a canonical URL for ErrorDocument, the result will be a 200-OK server response (see the notes in the DirectoryIndex documentation). Better to return a 404 response, and then use your catch-all 301 redirect to pass the client's request for the error document on olddomain over to newdomain *after* the 404 response.
ErrorDocument 404 /directory/index.php
#
RewriteEngine on
RewriteRule ^directory http://www.newdomain.com/index.php [R=301,NC,L]
Just in case: Don't put comments after your directives, put them on a new line. Comments appended to directives can cause Apache Warnings, which will slow down your server, even if the warnings don't appear in the error log because your loglevel is set higher than "Warn".
Jim