I am trying to use the following:
Redirect 301 /example/cookies http://test.butterscotch.co.uk/cookies?ref=test
Which ends up redirect to:
http://test.butterscotch.co.uk/cookies?ref=testexample/cookies
However if I do:
Redirect 301 /example/cookies/ http://test.butterscotch.co.uk/cookies?ref=test
And I try the URL:
http://oldhost.com/example/cookies/ (with the trailing slash)
it redirects to the new url correctly.
I need to be able to use the Redirect so it doesn't have to have the trailing slash.
Not sure what's causing your first issue, but the Redirect
directive is probably not what you want when you're working with a query string in the redirect target. The `Redirect directive kind of links two URL paths together, so if I have a rule like:
Redirect /abc /xyz
and I go to /abc/
, I'll obviously get redirected to /xyz/
, and if I go to /abc/def/g
I'll get redirected to /xyz/def/g
. When I have a query string in the mix:
Redirect /abc /xyz?i=123
and I go to /abc/def/g
, I'll end up getting redirected to /xyz?i123/def/g
, which obviously isn't what I want.
Try using RedirectMatch
instead:
RedirectMatch 301 /example/cookies/?$ http://test.butterscotch.co.uk/cookies?ref=test
or using mod_rewrite:
RewriteEngine On
RewriteRule ^example/cookies/?$ http://test.butterscotch.co.uk/cookies?ref=test [L,QSA,R=301]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.