.htaccess没有问号的重定向

时间:2012-12-05 02:49:35

标签: .htaccess redirect

我希望将网址http://www.example.com/user_pages/home_0.shtml?page=Home重定向到http://www.example.com/。我使用以下RedirectMatch重定向到http://www.example.com/?

RedirectMatch 301 ^/user_pages/home_0.shtml http://www.example.com/?

我希望有人可以帮我弄清楚如何删除拖尾问号。我明白这就是我设置它的方式,但这是我能够达到的最大匹配能力。

次要问题,但我认为这与我在这里所做的一致。我有以下RedirectMatch设置:

RedirectMatch 301 ^/user_pages/contactus_0.shtml http://www.example.com/help.php?section=contactus&mode=update

我正在尝试将http://www.example.com/user_pages/contactus_0.shtml?page=Contact%20Us重定向到http://www.example.com/help.php?section=contactus&mode=update,但我最终会使用http://www.example.com/help.php?section=contactus/user_pages/contactus_0.shtmlmode=update。我理解这是由额外的查询字符串引起的,但我对如何修复感到失望。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

删除查询的的一种方法是:

RewriteEngine On
#Test for a query with `page=`
RewriteCond %{QUERY_STRING} ^page=.*$   
RewriteRule .* http://www.example.com? [L,R=301]

最后会移除查询,包括

关于问题的最后部分,请查看我的评论。

相关问题