重定向所有非WWW到www。对于CakePHP的网站 [英] redirect all non www to www. for Cakephp site
问题描述
ALLM我是有在重定向非WWW网页的WWW的一些问题。我的CakePHP的网站网页。
Hi allm i'm having some issues in redirecting the non www pages to the www. pages for my cakephp site.
我试过
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
但它似乎并没有工作。
but it doesn't seem to work.
我的CakePHP的应用程序驻留在一个子文件夹。例如。 www.domain.com/my
。
My cakephp app resides in a subfolder. eg. www.domain.com/my
.
我已经添加了上述code到根文件夹, www.domain.com /
i've added the above code to the root folder, www.domain.com/
有什么建议?谢谢?
*更新
这是我的.htaccess文件
This my .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^.*$ http://www.domain.com%{REQUEST_URI} [R=301,L]
我得到一个额外的 Web根目录/的index.php?URL =
插入网址。而不是 www.domain.com/my/apple
,我得到 www.domain.com/my/webroot/index.php?url =苹果
i'm getting an extra webroot/index.php?url=
inserted into the url. Instead of www.domain.com/my/apple
, i'm getting www.domain.com/my/webroot/index.php?url=apple
感谢所有一次。
推荐答案
您code是不完全正确。见下文。
Your code is not quite right. See below.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^.*$ http://www.domain.com%{REQUEST_URI} [R=301,L] # <-- Mind the 'L'!
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
这篇关于重定向所有非WWW到www。对于CakePHP的网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!