如何使用参数重定向页面?

发布于 2024-10-21 18:58:17 字数 740 浏览 2 评论 0原文

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/database/mnop.html?p=167
http://stackoverflow.com/order/anything.html?mode=new
http://stackoverflow.com/checkout/something.html?mode=old

我想将所有类似这样的网址重定向到:

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

请suugest me。

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/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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风月客 2024-10-28 18:58:17

那么您想删除所有 URL 参数吗?鉴于这个问题被标记为 .htaccess,我假设这就是您想要用来进行重定向的内容。

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

这条规则基本上是说,给我所有格式为 *?* 的内容,然后忽略问号后面出现的所有内容。

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.

无语# 2024-10-28 18:58:17

假设您正在谈论一个 Web 服务器,并且该服务器是 apache,请查看 mod_rewrite。

http://www.elated.com/articles/mod-绝对初学者重写教程/

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/

瑶笙 2024-10-28 18:58:17

试试这个代码
但在前端网络服务器(nginx 等)中执行此操作的最佳方法

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

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文