【问题标题】:301 for urls indexed by google containing /index.php/*301 用于 google 索引的包含 /index.php/* 的 url
【发布时间】:2012-05-13 23:05:36
【问题描述】:

我正在尝试使用 301 将 google 索引的旧网址重定向到新网址

我需要以下 301 的重写规则示例吗? http://www .example.com/index.php/ * / */ ** 是通配符)到以下http://www.example.com/*/*/*

这样,当用户点击 google 索引的带有 index.php 的旧网址时,他们会被重定向到不带 index.php 的新网址。

有什么想法吗?

最好的,

【问题讨论】:

    标签: linux apache .htaccess mod-rewrite


    【解决方案1】:

    您可以使用 mod_alias:

    RedirectMatch 301 ^/index.php/(.*)$ /$1
    

    或者使用 mod_rewrite:

    RewriteRule ^index.php/(.*)$ /$1 [R=301,L]
    

    但是,请注意,如果您有重写规则将请求重写为指向 index.php,您将获得重定向循环。所以你需要在规则中添加一个条件:

    RewriteCond %{THE_REQUEST} ^/index.php
    RewriteRule ^index.php/(.*)$ /$1 [R=301,L]
    

    这可确保实际请求是针对index.php 而不是内部重写的 URI。

    【讨论】:

    • 我已经尝试过您的解决方案,但我仍然遇到问题。我认为 RedirectMatch 将成为我正在寻找的解决方案但是当我添加到我的 htaccess 时,当我访问 url ../index.php/music/2222/playlisttitle 我得到 ../music/2222/playlisttitle?rewrite=2 url ../music/2222/playlisttitle 运行正常,仍然需要摆脱那个@ 987654328@ 在 url 的末尾我有一个重写规则,它摆脱了 index.php 使用 ?rewrite=2 查询如下RewriteCond %{REQUEST_URI} /index\.php RewriteRule (.*) index.php?rewrite=2 [L,QSA]
    • 您希望重定向从查询字符串中删除rewrite=2? RedirectMatch 不会匹配查询字符串。
    • 看起来成功了,我只是从现有规则中删除了 ?rewrite=2 。此时看起来一切正常。谢谢!!
    猜你喜欢
    • 2020-07-07
    • 2012-01-27
    • 2017-03-09
    • 1970-01-01
    • 2011-07-02
    • 2017-12-30
    • 1970-01-01
    • 1970-01-01
    • 2017-01-15
    相关资源
    最近更新 更多