【问题标题】:.htaccess; Too many redirects if two different redirects in .htaccess.htaccess;如果 .htaccess 中有两个不同的重定向,则重定向过多
【发布时间】:2017-02-13 11:15:52
【问题描述】:

我有两种类型的网址:

http://www.example.com/?content=contact_form.php

http://www.example.com/?content=product.php&id=20

我像这样更改了我的整个 URL 系统:

http://www.example.com/file/contact_form

http://www.example.com/product/I-m-the-title/20

当然,我使用 .htaccess 进行了 301 重定向来告诉 Google 和公司。新网址。

我是这样设计的:

# Rewrite URLs

RewriteEngine On
RewriteRule ^(ignore)($|/) - [L]
RewriteRule ^file/([^/]*)$ /?content=$1.php [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /?content=$1.php&title=$2&id=$3 [L]


# Redirect old URL to new URL

RewriteCond %{QUERY_STRING} ^content=contact\_form\.php$
RewriteCond %{REQUEST_URI} ^\/$
RewriteRule .* http://www.example.com/file/contact_form? [R=301,L]

RewriteCond %{QUERY_STRING} ^content=product\.php&class=I-m-the-title$
RewriteCond %{REQUEST_URI} ^\/$
RewriteRule .* http://www.example.com/I-m-the-title/Test/20? [R=301,L]

我的问题:

它非常适合:http://www.example.com/?content=product.php&id=20

但是对于http://www.example.com/?content=contact_form.php,我收到的消息是由于重定向过多而无法打开它。

有人知道我做错了什么吗?我希望有人能尽快帮助我,因为我必须在 Google 误解它之前修复它。

【问题讨论】:

    标签: php apache .htaccess redirect mod-rewrite


    【解决方案1】:

    您的规则会导致无限循环,因为它会一次又一次地将您的 uri 重写到同一位置,从而覆盖您的内部和外部重定向。要修复重写循环,请在 htaccess 顶部添加以下内容

    RewriteEngine on
    
    RewriteCond %{ENV:REDIRECT_STATUS} 200
    RewriteRule ^ - [L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多