Forum Moderators: phranque

Message Too Old, No Replies

Importance of url redirect

redirect, 303 rewrite urls

         

dave_c00

2:07 pm on Sep 2, 2009 (gmt 0)

10+ Year Member



Hi,

I have been using the rewriterule for years now to make all my links within my site nice and search engine friendly.

However it was not until today that I heard about redirecting the old urls to the nice new furls.

If I have a url:

http://www.example.com/product/123

It loads the page http://www.example.com/product.php?id=123 which is fine.

If the user types in http://www.example.com/product.php?id=123 I think the correct thing to do is redirect them to http://www.example.com/product/123 right?

If this is the case do I use rewritecond to deal with the vars and then redirectmatch?

Thanks in advance,

Dave

jdMorgan

2:15 pm on Sep 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do not mix mod_rewrite (RewriteRule & RewriteCond) with mod_alias (RedirectMatch) directives. If you do so, you do not strictly control the directives' order of execution. A good rule of thumb is that if you use mod_rewrite for any redirects or rewrites, then use it for all. Otherwise, a change of hosts or a server upgrade may 'break' your site by changing the relative execution order of mod_rewrite and mod_alias.

You surmise correctly that you should externally redirect the old 'dynamic' URLs to their new static equivalents.

There's a trick to it though, because the commonly-attempted "simple" solution leads to an "infinite" rewrite/redirect loop. The solution is to use a RewrietCond testing THE_REQUEST, REDIRECT_STATUS, or an ENV: variable that you have previously defined, so that only *direct client requests* for the dynamic URL are redirected (and not internal requests resulting from previously executing your friendly-URL-to-script rewriterule).

Jim