正则表达式RedirectMatch删除问号和查询字符串参数

时间:2012-12-17 20:12:14

标签: regex .htaccess redirect joomla

我有一个不再是用户日历组件的Joomla网站,我需要将所有旧网址重定向回主页。网址看起来像这样......

http://www.example.com/week/?date=2006-03-05&print=1&tmpl=component
http://www.example.com/week/?date=2010-09-12
http://www.example.com/week/?date=2007-04-01&print=1&tmpl=component

我已尝试在.htaccess文件中编写RedirectMatch以删除域后的所有内容,但我只能从URL中删除周/,问号和参数仍然存在。这会出现某些参数的问题,这些参数会删除模板,模块或格式化页面以进行打印。

有人可以提出解决方案吗?这是我到目前为止所尝试的......

RedirectMatch 301 ^/week/\?.* http://www.example.com
RedirectMatch 301 ^/week/\?(.*) http://www.example.com
RedirectMatch 301 ^/week/\?+.+ http://www.example.com
RedirectMatch 301 ^/week/\?+(.*) http://www.example.com

没有开头插入符号的相同规则......

RedirectMatch 301 /week/\?.* http://www.example.com
RedirectMatch 301 /week/\?(.*) http://www.example.com
RedirectMatch 301 /week/\?+.+ http://www.example.com
RedirectMatch 301 /week/\?+(.*) http://www.example.com

2 个答案:

答案 0 :(得分:1)

修改:

对于网址:

http://example.com/week/?date=2010-09-12

你可以尝试这条规则:

 RewriteEngine on
 RewriteRule ^.*week/?$ www.example.com [R]

答案 1 :(得分:0)

哟可以试试这个:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^.*/week/$
RewriteRule .*   http://www.example.com/? [R=301,DPI,L]

将删除从/week和QUERY STRING开始的URI部分,仅保留:

http://www.example.com/

更新:

添加[DPI]标志以确保删除路径。

相关问题