Forum Topic: Redirect 301 url with ampersand

Forum: .htaccess Forum : Redirecting • Posted by Jeroen • Updated:

Hi Jeff,

After spending more than an hour on Google and your book trying to find a solution for a redirection, I have to give up.

All I want to do is to redirect urls like this

example.com/dir/pageslug&h=tAQEgErIi&s=1

to this

example.com/dir/pageslug

I have tried so many combinations, but I’m stuck with the ampersand.

btw Can an ampersand be treated as a query string? Or under which category does it fall?

Thanks

2 Replies to “Redirect 301 url with ampersand”

Posted by Jeff Starr

Hmmm.. how about something like this:

RedirectMatch 301 ^/dir/(pageslug)(\&(.*)) http://example.com/$1

I got this to work on my server, but it may need some fine-tuning to match exactly what you’re after. I think the key may be to escape the ampersand..?

Posted by Jeroen •

Thanks Jeff, it was indeed the ampersand escape that did the trick. I managed to get it working using

RedirectMatch 301 ^/dir/pageslug\&(.*) http://dir/pageslug