Forum Moderators: phranque

Message Too Old, No Replies

Any way of improving this rewriterule?

         

BenSeb

5:24 pm on Mar 13, 2008 (gmt 0)

10+ Year Member



Hi

Due to a bit of bad planning, we've recently changes some of our URL schemes.

We used to have

[domain.com...]
[domain.com...]
[domain.com...]

Now we're dropping the postcode to make the URLs more friendly

[domain.com...]
[domain.com...]
[domain.com...]

However, I'm sure you can see that our old URL will clash with the new.

the main concern is that any published links for

[domain.com...]

will try to push through to the new venue page

As the postcode is a specific format, I'm trying to place a rewrite rule infront of the venue rewrite rule to catch the old URLs

We need to match postcodes such as:

M1
M26
L1
SW1
SW1A

My current rule is:

RewriteRule ^whats-on/([^/]+)/[A-Za-z][A-Za-z]?[0-9][0-9]?[A-Za-z]?/$ /keyword/$1/ [L,R=301]

Quite complex, any way to improve upon this?

g1smd

8:19 pm on Mar 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Postcode will always contain one or two digits, so you just need to test if there is one or two digits in that section of the URL.

You need to make sure that venue never contains any digits, but it can contain three or more digits.

jdMorgan

9:16 pm on Mar 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your example URLs don't match your rule pattern exactly, but it looks to me as though you are dropping the "tail" - that is, dropping the venue and event from the requested URL-path. I'd suggest using the [NC] flag and specific quantifiers to shorten the patterns:

RewriteRule ^whats-on/([^/]+)/[a-z]{1,2}[0-9]{1,2}[a-z]?/(.*)$ /keyword/$1/$2 [NC,R=301,L]

Jim