|301 redirect vs rewrite in httpd.conf|
Which is better for a redirect?
I'm trying to clean up my httpd.conf file a bit, and have a lot of 301's from a site upgrade.
redirect 301 /advertising.html http://www.example.com/ads/
I'm wondering, is it better to use mod_rewrite instead? eg:
RewriteRule ^advertising.html$ http://www.example.com/ads/ [R=301,L]
Keeping in mind that these are in the httpd.conf, NOT the .htaccess. And there are other mod_rewrite rules due to some SEO friendly url plugs (for phpbb, specifically).
Thanks for any advice!
[edited by: jdMorgan at 2:43 am (utc) on Jan. 9, 2010]
[edit reason] example.com [/edit]
If you have any rules using RewriteRule, use RewriteRule for all of them.
Never mix Redirect/Redirectmatch in the same .htaccess file as RewriteRule.
Thanks for the response! I believe I've heard that before...nevertheless, I still have both 'versions' in the same setup. Remember though, I'm talking httpd.conf, not .htaccess.
Does that make a difference? What's the reasoning behind not using both in the same setup?
You can't always be sure which set Redirect/RedirectMatch or RewriteRule will be invoked first, so use RewriteRule for all of them.
All mod_alias directives will be processed first, followed by all mod_rewrite directives.
Change the module load-list order, and this reverses.
Code function depended on the relative module execution order? -- Ooops! I hope someone's there who remembers this info and can figure it out...
Above recommendation seconded -- and not lightly.
Hmm - Well in my conf right now are 10 redirects first - and then later on, rewrite is turned on and there are a series of rewrite rules.
Does that affect execution order? Or is it just 'cleaner' to have all the 301's in the same format? Is there any benefit to performance?
It makes no difference what order you put the two modules' directives in your file. All mod_alias directives *may* get processed first, or all mod_rewrite directives may get processed first, but it will be one or the other, depending on the LoadModule order. Configuration and .htaccess code is not a sequential 'program' but rather a list of 'function tokens' addressed to the various Apache modules, each one of which in turn 'scans' the file and handles the requested functions.
If, through some future event such as you changing jobs, selling the site, changing hosting, or whatever, you lose control of the LoadModule order, then the code may suddenly stop working, and no-one will know why...
Anyway, I'm not going to beat a dead horse; We've cited best-practice, and you may ignore it if you wish.
Thanks - Just trying to understand 'why' it's best practice. I'll give it a shot