如何将www URL改写为非www URL


How to rewrite www URL to non-www URL?

我在我的。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]

但是这会导致"too many redirects"

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