我想在 .htaccess 中重定向每个包含“?”的 URL。字符添加到我网站的根目录 (domain.com)。
我读过这个:
301-htaccess-redirect-with-special-characters
/how-to-make-htaccess-rule-for-a-url-with-specific-characters
但是我还是不知道该怎么做。我只知道一点正则表达式。
示例 Urls 我想重定向到我网站的根目录:
http://www.portaltarot.com/index.html?url=/MHL-Papus.html http://www.portaltarot.com/index.phpindex.php?Itemid=249
最佳答案
你需要使用 mod_rewrite 来做到这一点,所以像这样:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^url=/MHL-Papus.html$
RewriteRule ^index\.html$ / [L,R=301]
RewriteCond %{QUERY_STRING} ^Itemid=249$
RewriteRule ^index\.phpindex\.php$ / [L,R=301]
关于regex - 301 .htaccess 从具有 "?"字符的 URL 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24614452/