2
votes

I am trying to organise a simple 301 redirect in my .htaccess file and having some issues.

My current code looks:

RewriteRule /contact/ http://www.example.com/connect/ [R=301,L,QSA]

Though when you enter in: http://www.example.com/contact/

It redirects okay, though places in a query string: http://www.example.com.au/connect/?field=contact

Which then makes everything blow-up. I have the 301 on the top of my .htaccess file. I am not sure why this is happening.

Any suggestions would be really appreciated.

2
what if you try RewriteRule http://www.example.com/contact/ http://www.example.com/connect/ [R=301,L,QSA] ? - maxpovver
and also try RewriteRule contact/ http://www.example.com/connect/ [R=301,L,QSA] - maxpovver
@maxpovver Thank you for your ideas. Both of your solutions didn't really achieve the same result. I think it has to do with the wildcards in the URL. Adding ^/? into the rewrite seems to have done the trick. - Brandrally

2 Answers

2
votes
RewriteRule ^/?contact/?$ http://www.example.com/connect/? [R=301,L,QSA]

Empty question mark at the end is important as it will discard the original query string from url. If you are u

1
votes

Please also try this one:

RewriteRule ^contact/$ http://www.example.com/connect/? [L,R=301]