简体   繁体   English

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

[英]Regex RedirectMatch to Remove Question Mark and Query String Parameter

I have a Joomla site that no longer users a calendar component, and I need to redirect all the old URLs back to the homepage. 我有一个Joomla网站,该网站不再使用日历组件,并且需要将所有旧的URL重定向回首页。 The URL's look like this... 网址看起来像这样...

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

I've tried writing a RedirectMatch in the .htaccess file to remove everything after the domain, but I am only able to remove week/ from the URL, the question mark and parameters remain. 我尝试在.htaccess文件中编写一个RedirectMatch来删除域之后的所有内容,但是我只能从URL中删除week /,问号和参数仍然保留。 This presents issues with certain parameters which remove the template, modules or format the page for printing. 这会带来某些参数问题,这些参数会删除模板,模块或格式化页面以进行打印。

Can anyone suggest a solution? 谁能提出解决方案? Here is what I've tried so far... 到目前为止,这是我尝试过的...

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

And the same rules without the opening caret... 同样的规则没有插入尖号...

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

Edit: 编辑:

For url: 对于网址:

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

Could you try this rule: 您可以尝试以下规则:

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

Yo may try this: 您可以尝试以下方法:

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

Will remove the part of the URI starting at /week and the QUERY STRING, leaving only: 将删除从/week开始的URI部分和QUERY STRING,仅保留:

http://www.example.com/

UPDATED: 更新:

Added [DPI] flag to make sure the path is removed. 添加了[DPI]标志,以确保删除路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM