Welcome to WebmasterWorld Guest from 54.160.131.144

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

301 redirect vs rewrite in httpd.conf

Which is better for a redirect?

     

madmatt69

8:13 pm on Jan 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm trying to clean up my httpd.conf file a bit, and have a lot of 301's from a site upgrade.

For example:

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]

g1smd

9:07 pm on Jan 8, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



If you have any rules using RewriteRule, use RewriteRule for all of them.

Never mix Redirect/Redirectmatch in the same .htaccess file as RewriteRule.

madmatt69

9:19 pm on Jan 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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?

g1smd

9:51 pm on Jan 8, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



You can't always be sure which set Redirect/RedirectMatch or RewriteRule will be invoked first, so use RewriteRule for all of them.

jdMorgan

2:47 am on Jan 9, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



All mod_alias directives will be processed first, followed by all mod_rewrite directives.
Or vice-versa...

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.

Jim

madmatt69

4:28 pm on Jan 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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?

jdMorgan

5:09 pm on Jan 9, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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.

Jim

madmatt69

8:31 pm on Jan 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks - Just trying to understand 'why' it's best practice. I'll give it a shot