使用 Kohana Framework 将 www 重定向到非 www
我正在使用 Kohana 设置来重写 index.php 以获取干净的 URL。我有以下 htaccess 文件,该文件适用于根域。但是,如果有人尝试访问 www.domain.com/learn,它将重定向到domain.com/index.php/learn,这是不正确的。它应该重定向到domain.com/learn
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
#RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
#Redirect www to non-www
RewriteCond %{HTTP_HOST} ^www.ericleslie.com [NC]
RewriteRule ^(.*)$ http://ericleslie.com/$1 [L,R=301]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]
I'm using Kohana setup to rewrite index.php for clean URLs. I have the follow htaccess file which works fine for the root domain. However if someone tries going to www.domain.com/learn it will redirect to domain.com/index.php/learn which is incorrect. It should redirect to domain.com/learn
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
#RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
#Redirect www to non-www
RewriteCond %{HTTP_HOST} ^www.ericleslie.com [NC]
RewriteRule ^(.*)$ http://ericleslie.com/$1 [L,R=301]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查您的
bootstrap.php
。默认情况下,Kohana::init()
中的index_file
未设置为FALSE
。Check your
bootstrap.php
.index_file
inKohana::init()
isn't set toFALSE
by default.