【问题标题】:mod_rewrite redirect complex old url to new onemod_rewrite 将复杂的旧网址重定向到新网址
【发布时间】:2018-02-14 08:24:27
【问题描述】:

我有一个旧网站用于特定页面的复杂 URL。在更新后的新网站中,这个 URL 变得更短,更简单(事实上,旧的已经不存在了)。当在浏览器中输入或从电子邮件链接到时,我正在尝试将旧 URL 重定向到新的、更短且实际存在的 URL。

我已经尝试了无数的事情,但我对 mod_rewrite 相关的一切都非常不擅长。不用说,我正在尝试在我的 .htaccess 文件中执行此操作。

旧网址: www.domain.com/Event.211.0.html?&tx_calendar_pi1%5Bf1%5D=1061&tx_calendar_pi1%5Bf4%5D=1519102800&cHash=b884377a19d2bc32558d8c3ae232bedf

新网址: www.domain.com/events/februarypowerlunch/

有什么建议吗?

【问题讨论】:

    标签: apache .htaccess redirect mod-rewrite


    【解决方案1】:

    试试下面的代码:

    RewriteEngine On 
    RewriteCond %{REQUEST_URI}  !^/events/februarypowerlunch/
    RewriteCond %{THE_REQUEST} ^(.*)\?(.*)\%(.*)\%(.*)=(.*)\%(.*)\%(.*)$ 
    RewriteRule ^     /events/februarypowerlunch/?  [R=302,L]
    

    如果没问题,请将302 更改为301 以获得永久重定向。

    更新:

    如果您只想匹配 Event.211.0.html,请执行以下操作:

    RewriteEngine On 
    RewriteCond %{REQUEST_URI}  !^/events/februarypowerlunch/
    RewriteRule ^(e|E)vent\.211\.0\.html    /events/februarypowerlunch/?  [R=301,L]
    

    【讨论】:

    • 感谢您的建议 - 但是 - 此代码如何将特定、复杂、唯一的 URL 重定向到 /events/februarypowerlunch/?
    • 放在主目录的.htaccess文件中
    • 难以置信,我不知道怎么做 - 但它工作得很好。谢谢你帮我!!!!
    • 除了,其他包含 % 和 ?和 = 现在也重写到那个新的 URL。这不应该发生。有没有办法让“Event.211.0”成为将被重写的 URL 的一部分?那么,当提交/输入的 URL 包含“Event.211.0”时,它只重写新 URL?
    • 好的,我来做,我会更新给你来解决这个问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-01
    • 2015-08-02
    • 1970-01-01
    • 2019-04-08
    • 2021-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多