如何将www URL重写为非www URL?

时间:2015-08-13 08:39:25

标签: php apache .htaccess mod-rewrite kohana

我的.htaccess文件中有以下规则,我想知道如何将我的URL从www.mydomain.com重写为mydomain.com,我正在使用Kohana 3.2并且没有找到有关它的信息。

RewriteEngine On
RewriteBase /

RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* index.php/$0 [PT]

我尝试了以下内容:

    RewriteEngine On
    RewriteBase /

    RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
    RewriteRule ^(.*)$ http://mydomain/$1 [L,R=301,NC]

    RewriteRule .* index.php/$0 [PT]

但它导致“太多重定向”

1 个答案:

答案 0 :(得分:0)

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%2://%1%{REQUEST_URI} [L,R=301]