【问题标题】:How to rewrite www URL to non-www URL?如何将www URL重写为非www URL?
【发布时间】:2015-11-06 03:10:01
【问题描述】:

我的 .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]

但这会导致“重定向过多”

【问题讨论】:

标签: php apache .htaccess mod-rewrite kohana


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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-16
    • 2011-06-24
    • 1970-01-01
    • 2017-05-03
    • 2015-08-03
    • 2019-03-09
    • 2011-11-05
    • 2013-12-20
    相关资源
    最近更新 更多