开发者

How to redirect pages with a parametre?

http://stackoverflow.com/questions/abcd.html&p=1
http://stackoverflow.com/answers/wxyz.html&p=5
http://stackoverflow.com/database/mnop.html&p=167

http://stackoverflow.com/questions/abcd.html?p=1
http://stackoverflow.com/answers/wxyz.html?p=5
http://stackoverflow.com/开发者_StackOverflow中文版database/mnop.html?p=167
http://stackoverflow.com/order/anything.html?mode=new
http://stackoverflow.com/checkout/something.html?mode=old

I want to redirect all urls like these to:

http://stackoverflow.com/questions/abcd.html
http://stackoverflow.com/answers/wxyz.html
http://stackoverflow.com/database/mnop.html
http://stackoverflow.com/order/anything.html
http://stackoverflow.com/checkout/something.html

Please suugest me.


You want to remove all URL parameters then? Given that this question is tagged to .htaccess, I assume that's what you want to use to do your redirect.

RewriteRule ^(.*)\?.*$  $1  [L,R=301]

This rule basically says, given me everything that is in the format *?*, and then just ignore all the content that occurs after the question mark.


Assuming you're talking about a web server, and that server is apache, take a look at mod_rewrite.

http://www.elated.com/articles/mod-rewrite-tutorial-for-absolute-beginners/


Try this code
But the best way doing this in frontend webserver (nginx e.t.c)

if (preg_match('@^(.+)\?.+@Uis', $_SERVER['REQUEST_URI'], $matches)) {
  header('Location: ' . $matches[1]);
  exit;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜