Mod rewrite

Hi

I have a website with the following url rewrite set

RewriteRule ^Cat-(.*)-(.*).html$ section.php?cat_name=$1&cat=$2

I’d like to change the URLs from

www.mydomain.co.uk/Cat-blah-1.html

to

www.mydomain.co.uk/L1-blah-1.html

I can change the rewrite rule to

RewriteRule ^L1-(.*)-(.*).html$ section.php?cat_name=$1&cat=$2

But is there a way I can redirect any pages listed in search engines so that

www.mydomain.co.uk/Cat-blah-1.html

is redirected

www.mydomain.co.uk/L1-blah-1.html

Thanks

rt,

Yes, that’s a simple replacement redirection. See the sample code in my signature’s tutorial.

Regards,

DK

Got it. Thanks DK

Awwww :frowning:

I did have it. But I have returned a few weeks later to admire my break through and I can find no evidence of the work I did.
What a bad trip!

I think I did something like this but it isn’t right.
RewriteEngine on
RewriteRule ^L1-(.)-(.).html$ Cat-$1-$2.html [N,L]

Anybody help me?

rt,

Based on your sample characters (lowercase for $1 and digits for $2), I’d use:

RewriteEngine on
RewriteRule ^L1-([a-z]+)-([0-9]+)\\.html$ section.php?cat_name=$1&cat=$2 [L]

When you are in a position to specify the characters used in your links, use them in the mod_rewrite code, too. It may be a small security issue to you but it would make hacking much easier for someone trying to break into your website. Besides, the inappropriate use of the :kaioken: EVERYTHING :kaioken: atom is the first indication that the coder has no idea what he/she is doing (and generally results in looping code).

Regards,

DK

Thanks DK

I appreciate the heads up on the security gap. But $1 is a often a mix of Uppercase and lower case so would that make

([a-z]+)

this

([A-Z]+)

As important as the security issue is your suggestion doesn’t work for the redirect I need.

For example I need:

http://www.myOLDdomain.com/Cat-Harley_Discount_Parts-39.html

to go to

http://www.myNEWdomain.co.uk/L1-Harley_Discount_Parts-39.html

I.E. the ‘Cat’ in the old domain becomes a ‘L1’ in the new domain.

Thanks for getting back so promptly