Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

apache - Remove query string from redirected URL with htaccess

I'm using the following code to redirect traffic to a spesific page (this traffic is coming via google from an old site which used to use my servers ip)

RewriteRule ^viewtopic.php?/?$ http://www.myurl.org.uk/ [L,R=301]

As I understand it this ^viewtopic.php?/?$ should strip away the query string but it isn't working. Any help appreciated.

Example URL

http://www.myurl.org.uk/viewtopic.php?f=3&t=44207&start=2265

Output when redirected

http://www.myurl.org.uk/?f=3&t=44207&start=2265
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You were close to the answer... You have the ? on the wrong side. Put it on the redirect side to strip off the query string:

RewriteRule ^viewtopic.php http://www.myurl.org.uk/? [L,R=301]

In a 301 redirect, mod_rewrite will normally append the full query string. But placing a ? at the end of your rewritten URL without a corresponding [QSA] ("querystring append") flag will instruct it instead to use the blank query string you supplied.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...