【问题标题】:Redirecting non www to www in CakePHP using app/webroot使用 app/webroot 在 CakePHP 中将非 www 重定向到 www
【发布时间】:2011-09-24 13:42:51
【问题描述】:

大师

我正在尝试将访问http://domain.com 的任何用户重定向到http://www.domain.com。我在 SO 上找到了很多不同的方法,但我需要让它们适合 CakePHP 的动态应用程序配置。

目前,这是我的 .htaccess 读取的内容:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^$ app/webroot [L]
    RewriteRule (.*) app/webroot [L]
</IfModule>

我在 Slicehost 切片上运行 Ubuntu 10.04。

非常感谢任何帮助。谢谢。

更新 - 解决方案 - 感谢 Rob Wilkerson

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{HTTP_HOST} !^www\.myapp\.com [NC]
    RewriteRule ^(.*)$ http://www.myapp.com/$1 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ app/webroot/$1 [QSA,L]
</IfModule>

【问题讨论】:

    标签: apache .htaccess cakephp redirect ubuntu


    【解决方案1】:

    来自我自己的一个应用程序:

    <IfModule mod_rewrite.c>
      RewriteEngine On
    
      RewriteCond %{HTTP_HOST} !^www\.myapp\.com [NC]
      RewriteRule ^(.*)$ http://www.myapp.com/$1 [R=301,L]
    
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
    </IfModule>
    

    【讨论】:

    • 嘿,它完成了这项工作,但我的 JS 和 CSS 现在都坏了。
    • 你认为这可能与 index.php?=url=$1 ... 行有关吗?我不在我的应用中使用该层次结构。
    • 好的,很抱歉评论垃圾邮件 - 但它有效!我刚刚将 index.php?url= 替换为 app/webroot/ !谢谢!
    猜你喜欢
    • 1970-01-01
    • 2018-06-06
    • 1970-01-01
    • 2011-01-05
    • 2012-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多