【问题标题】:301 working on some URLs and not on others in htaccess301 在某些 URL 上工作,而不是在 htaccess 中的其他 URL
【发布时间】:2017-09-03 09:20:03
【问题描述】:

您好,我在 301 重定向时遇到 .htaccess 问题。

90% 的 url 上一切看起来都很好,但对于任何单独的博客文章重定向都没有。

这是他们不重定向的代码:

RewriteRule ^blog-article.php?id=38 blog-post/xxxx-xxxxxx-xx-x-xxxxxxx/9/ [L,NC,R=301]
RewriteRule ^blog-article.php?id=34 blog-post/xxxxxxx/4/ [L,NC,R=301]

但所有其他 301 重写工作,它们看起来像这样:

RewriteRule ^old-url-portfolio/(.*)$ page/new-url-portfolio/$1 [L,NC,R=301]
RewriteRule ^Portfolio/Detail/(.*)$ portfolio/$1 [L,NC,R=301]

RewriteRule ^old-url/7/ page/new-url/ [L,NC,R=301]
RewriteRule ^contact-us-old/ page/contact-us-new/ [L,NC,R=301]
RewriteRule ^blog.php page/blog/ [L,NC,R=301]

我找不到他们为什么不工作,不是因为那些不工作的是个别文件,因为 blog.php 文件正在被发送到新页面。

任何想法将不胜感激:)

【问题讨论】:

    标签: apache .htaccess redirect mod-rewrite


    【解决方案1】:

    您无法匹配 RewriteRule 模式中的查询字符串。要将 blog-article.php?id=123 重定向到不同的位置,您需要使用 RewriteCond 指令匹配 %{QUERY_STRING}。

    RewriteCond %{QUERY_STRING} ^id=123$
    RewriteRule ^blog-article.php$ /location/? [L,R]
    

    注意:目标路径末尾的 ? 很重要,因为它会丢弃旧的查询字符串。

    【讨论】:

      【解决方案2】:

      找到一个解决方法,它接缝的问题是 ?id=number 所以我只是这样做了:

      RewriteCond %{QUERY_STRING} ^id=38$
      RewriteRule ^blog-article\.php$ http://www.xxxxxxx.co.uk/blog-post/xxxx-xxxxxx-xxxx/9/ [R=301,L]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-04-29
        • 2023-03-04
        • 1970-01-01
        • 2020-12-30
        • 2011-09-18
        • 2017-12-20
        • 2013-02-10
        相关资源
        最近更新 更多