Hi all, Here's something that has stumped me today... I've added the following very basic mod_rewrite into an htaccess code for two blogs: RewriteEngine On RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L] (obviously changing new domain to for each respective blog) On one of the blogs I am achieving the correct effect - each blog post from the old domain is directed to the equivalent blog post on the new domain. On the other blog however, it is just redirecting to the index page of the new domain...to the best of my knowledge everything else is the same!! Any ideas?! Much appreciated Sam
Ha! apologies I've just worked it out! But I'mnot sure why it makes a difference so I'll post the changes here and maybe someone could explain why it has made a difference! Here is the mod_rewrite that I had in place that worked as I wanted (see above) #<IfModule mod_rewrite.c> #RewriteEngine On #RewriteBase /directory/ #RewriteCond %{REQUEST_FILENAME} !-f #RewriteCond %{REQUEST_FILENAME} !-d #RewriteRule . /directory/index.php [L] #</IfModule> RewriteEngine On RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L] And here's the one that didn't work: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /directory/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /directory/index.php [L] </IfModule> RewriteEngine On RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L] Basically, there are no hashes at the beginning of each line of the intial mod_rewrite rules....why does this make a difference?
You can put RewriteEngine On RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L] Code (markup): before <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /directory/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /directory/index.php [L] </IfModule> Code (markup): The RewriteRule in the Ifmodule executes and stops the rest of the code from executing, (before it can redirect). Place your rewriterules before the original code and you should be fine.