如何使用特殊 url 重定向 url?

How redirect urls with special url?

我想将这种类型url重定向到我的主页

http://www.mywebsite.com/index.php?showuser=

http://www.mywebsite.com/

我可以使用 .htaccess 执行此操作吗?怎么做。我试过了,但没有任何效果。

redirectMatch 301 /index.php?showuser= http://www.mywebsite.com

RedirectMatch 301 /index.php\?showuser\= http://www.mywebsite.com

您无法匹配 RedirectMatch 正则表达式中的查询字符串。您需要使用 mod_rewrite 和 %{QUERY_STRING} 变量:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^showuser=
RewriteRule ^index\.php$ /? [L,R=301]

RedirectRedirectMatch 都不能匹配查询字符串。 RedirectMatch 中的 ? 实际上意味着 "the previous character 0 or 1 times",并且将与 "index.php" 匹配。请注意,您也没有正确使用圆点。

您可以使用 mod_rewrite 解决此问题。确保它已启用,并且您允许覆盖 FileInfo。然后使用以下指令:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^showuser=$
RewriteRule ^index\.php$ / [R,L]

如果您希望在测试一切正常后永久重定向,请将 [R] 更改为 [R=301]