【问题标题】:Regex RedirectMatch to Remove Question Mark and Query String Parameter正则表达式 RedirectMatch 以删除问号和查询字符串参数
【发布时间】:2012-12-19 08:08:47
【问题描述】:

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

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 中删除 week/,问号和参数仍然存在。这会导致某些参数出现问题,这些参数会删除模板、模块或格式化页面以进行打印。

谁能提出解决方案?这是我迄今为止尝试过的......

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

【问题讨论】:

    标签: regex .htaccess redirect joomla


    【解决方案1】:

    编辑:

    对于网址:

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

    你能试试这个规则吗:

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

    【讨论】:

    • 感谢您的建议!但是由于某种原因,这些都不会触发匹配并且不会创建重定向。我得到一个动态 Joomla 404 错误页面。
    • 这很奇怪。您的 week 子目录是否有自己的 .htaccess 文件?
    • 不确定。文件夹结构如下: home/username/domain.com /domain.com/ 中只有一个 .htaccess 文件,home/ 或 home/username/ 中都没有 .htaccess 文件
    • 嗯,只是为了澄清一下:所有 .../week/... 链接都无效吗?我对 Joomla 不太熟悉,但我想到的文件夹是 http://www.example.com/week/ 。如果该路径存在,那里是否有 .htaccess 文件?
    • 不,该文件夹实际上并不存在于服务器上。从来没有,Joomla 组件只是简单地将 /week/ 添加到 URL 以使其对搜索引擎友好。所以唯一的htaccess文件位于home/username/domain.com的domains文件夹中
    猜你喜欢
    • 2022-01-22
    • 2014-05-21
    • 2010-12-22
    • 2015-12-31
    • 1970-01-01
    • 2012-02-29
    • 2012-02-26
    • 2011-10-02
    相关资源
    最近更新 更多