When doing research on 301 redirects in Apache, I've noticed there are two ways you can accomplish the redirect in the .htaccess file... Option 1 Options +Indexes Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^old.htm$ http://www.new.com/ [R=301,L] Option 2 redirect 301 /old.htm http://www.new.com/ Are there advantages / disadvantages to either? I'd be inclined to go with the second option for the simplicity, but perhaps I'm missing something? Any comments would be great, thanks!
I prefer to go with Option 1, as if you start using other rewrite rules for your website (or other websites), it'll be in the same format, where as with option 2, it's a different format to the rest of the rewrite rules.
I suspect that the first option gives you greater possibilities with how you want to control the rewrite. For instance, you can specify [R=301, NC, QSA, L] if you want the rewrite to be case-insensitive, have anything after the question mark appended and be the last one. I don't think you can do that with Redirect.
Option 2 is easier to read and understand for the webmaster. It is also "easier" to process for the web server. It does not allow wildcard characters and regular expressions. My conclusion is: - use option 2 when possible - use option 1 otherwise Jean-Luc
So if I'm trying to get everything under a parent directory to go to one URL (basically avoiding a canonical URL issue) would this be the most streamlined code for that? Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^test$ http://www.example.com/test/ [R=301] RewriteRule ^test/$ http://www.example.com/test/ [R=301] RewriteRule ^test/index(.*)$ http://www.example.com/test/ [R=301,L]
This is better: Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^test$ http://www.example.com/test/ [R=301] RewriteRule ^test/index(.*)$ http://www.example.com/test/ [R=301,L] Code (markup): This creates an infinite loop: RewriteRule ^test/$ http://www.example.com/test/ [R=301] Code (markup): Jean-Luc