【问题标题】:How to configure htaccess file for Cake 2.3.x on 1and1 shared hosting如何在 1and1 共​​享主机上为 Cake 2.3.x 配置 htaccess 文件
【发布时间】:2013-12-24 20:47:57
【问题描述】:

当我想在子文件夹中安装我的 Cakephp 应用程序时,使用默认的 cakephp htaccess 文件设置将无法在我的域上运行,而一切都在 localhost (xampp) 上运行

目标 => http://example.com/mycakeapp

安装需要 3 个 htaccess 文件:

根 .htaccess

#.htaccess 在根目录 重写引擎开启 RewriteBase /mycakeapp RewriteRule ^$ app/webroot/ [L] RewriteRule (.) app/webroot/$1 [L] 在应用程序.htaccess 中 重写引擎开启 RewriteBase /mycakeapp RewriteRule ^$ app/webroot/ [L] RewriteRule (.) app/webroot/$1 [L] 在 webroot .htaccess 中 重写引擎开启 RewriteBase /mycakeapp RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [QSA,L]

按照 cakephp 文档,并使用这些 htaccess 文件,我得到 error500 结果。 使用 RewriteBase / 而不是 /mycakeapp 会抛出 404 错误页面。

php 是 5.4 版本 我该如何解决这个问题?

【问题讨论】:

    标签: regex apache .htaccess cakephp mod-rewrite


    【解决方案1】:

    像这样设置你的规则:

    DOCUMENT_ROOT 中的.htaccess

    RewriteEngine on
    RewriteBase /
    RewriteRule (.*) mycakeapp/$1 [L]
    

    DOCUMENT_ROOT/mycakeapp 中的.htaccess

    RewriteEngine on
    RewriteBase /mycakeapp/
    RewriteRule (.*) app/webroot/$1 [L]
    

    DOCUMENT_ROOT/mycakeapp/app 中的.htaccess

    RewriteEngine on
    RewriteBase /mycakeapp/app/
    RewriteRule (.*) webroot/$1 [L]
    

    DOCUMENT_ROOT/mycakeapp/app/webroot 中的.htaccess

    RewriteEngine On
    RewriteBase /mycakeapp/app/webroot/
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    

    【讨论】:

    • 您好,感谢您的帮助。现在我可以看到我的应用程序了。但是,此设置将 mydomain.com/mycakeapp 重定向到 mydomain.com,就好像我的 cakeapp 安装在根文件夹中一样。实际上,我不需要这种重定向。我该如何更改?
    • 太棒了!非常感谢@anubhava :-)
    【解决方案2】:

    /dirCakePhp

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

    /direCakePhp/app

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

    /direCakePhp/app/webroot

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]
    </IfModule>
    

    只需在 RewriteRule 后添加 '/',

    并将 1and1 托管面板中的 PHP 版本更改为 => 5.2 添加 date_default_timezone_set('Europe/Paris');在 core.php 中

    【讨论】:

      猜你喜欢
      • 2018-08-05
      • 1970-01-01
      • 2015-05-27
      • 1970-01-01
      • 2012-07-10
      • 1970-01-01
      • 1970-01-01
      • 2014-09-05
      • 2010-11-27
      相关资源
      最近更新 更多