【问题标题】:redirect non-www to www resulting in loop address将非 www 重定向到 www 导致循环地址
【发布时间】:2015-10-12 13:38:38
【问题描述】:

我正在配置我的网站以将任何非 www 重定向到 www,但导致地址循环如下:

abc.com/www.abc.com/index.php/www.abc.com/index.php/www.abc.com/index.php/www.abc.com/index.php/www.abc.com/index.php ... and so on

下面是我的 .htaccess 文件。谁能帮我找出我的错误?

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^(/index\.php|/assets|/robots\.txt|/favicon\.ico)
RewriteRule ^(.*)\.html$ /index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^(/index\.php|/assets|/robots\.txt|/favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ www.%{HTTP_HOST}/index.php/$1 [R=301,L]
</IfModule>

<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

非常感谢,

【问题讨论】:

    标签: .htaccess no-www


    【解决方案1】:
    RewriteRule ^(.*)$ www.%{HTTP_HOST}/index.php/$1 [R=301,L]
                       ^---
    

    你忘了在主机名前加上http://,所以 Apache 重写为 LOCAL url

    试试

    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/index.php/$1 [R=301,L]
    

    改为。

    适用于的规则基本相同:

    <img src="www.example.com/kittens.jpg" />
    <img src="http://www.example.com/kittens.jpg" />
    

    【讨论】:

    • 我的错。在我清除了我的历史记录和 cookie 后,它终于可以工作了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-27
    • 2018-06-06
    • 1970-01-01
    • 1970-01-01
    • 2012-04-11
    • 2015-02-16
    相关资源
    最近更新 更多