Forum Moderators: phranque

Message Too Old, No Replies

redirect with mod_rewrite

from a url thats already been rewritten

         

stef25

9:32 am on Nov 9, 2005 (gmt 0)

10+ Year Member



using mod_rewrite, ive created a url in the format of domain.com/123.html from a long SE unfriendly url. id now like to redirect that url to something like domain.com/cat1/cat2/123.html

is that possible? what's the best way to go about it, to create a new rewrite rule, or just adjust the first rule?

so all together it would be

domain.com/index.php?lotsofnastycharacters - to
domain.com/123.html - to
domain.com/cat1/cat2/123.html

the_nerd

10:22 am on Nov 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try to see it the other way round:

1. shown to customer:
a) domain.com/123.html
b) domain.com/cat1/cat2/123.html

2. that's the way it really is:
domain.com/index.php?lotsofnastycharacters - to

You can simply add a second rule for domain.com/cat1/cat2/123.html . This way both URLs would work - but would eventually be picked up by SEs, looking like dup content.

So, you would want to add another rule that REDIRECTS (not rewrites)

domain.com/123.html -> domain.com/cat1/cat2/123.html ,
i.e. something like (untested...)

^([a-z0-9]+)\.html$ cat1/cat2/$1.html[R=301,NC]

This way, if the user types in test.html, his browser will reload the page and show the new name "cat1/cat2/test.html".

(finding errors is left as an exercise to the readers ;-)

nerd