views:

17

answers:

2

The following htaccess based redirection rule works fine:

Redirect 301 /content/category/2/24/30/ /new/c/url/

The problem is it works too well. If a user goes to

/content/category/2/24/30/50/50/

it will redirect to:

/new/c/url/50/50/

How can I get it to do a strict match? Either redirecting both examples to simply:

/new/c/url/

would be fine, otherwise ignoring the longer version is good too.

Thanks!

A: 

And the solution should be

RedirectMatch 301 ^/content/category/2/24/30/$ /new/c/url/

Basically you're saying the 30/ is the end of the string.

I can't try it so let me know if it's not working.

^ matches the beginning of a string and $ matches the end of a string.

Read this if you want to know more about it: http://www.regular-expressions.info/

dierre
+1  A: 

Redirect matches path prefixes and not just the whole path. If the given path prefix matches the requested path, the remaining path from the prefix on is appended to the replacement path.

So use RedirectMatch instead with ^ and $ marking the start and end of the path:

RedirectMatch 301 ^/content/category/2/24/30/$ /new/c/url/
Gumbo
Thanks it works.
Dan