且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 htaccess 从重定向的 URL 中删除查询字符串

更新时间:2023-02-23 08:32:11

您已经接近答案了...您的 ? 是错误的.将其放在重定向端以去除查询字符串:

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]

在 301 重定向中,mod_rewrite 通常会附加完整的查询字符串.但是在重写的 URL 末尾放置一个 ? 而没有相应的 [QSA] ("querystring append") 标志将指示它使用您提供的空白查询字符串.

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.