使用 Kohana Framework 将 www 重定向到非 www

发布于 2024-12-11 18:24:40 字数 863 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仅冇旳回忆 2024-12-18 18:24:40

检查您的 bootstrap.php。默认情况下,Kohana::init() 中的 index_file 未设置为 FALSE

Check your bootstrap.php. index_file in Kohana::init() isn't set to FALSE by default.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文