php .htaccess for cakephp
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1334746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.htaccess for cakephp
提问by MrG
I'm trying to get a CakePHP application to work. For this, I've set up a brand new Debian installation, updated the configuration and put everything in /var/www, which has the following content:
我正在尝试让 CakePHP 应用程序工作。为此,我设置了一个全新的 Debian 安装,更新了配置并将所有内容放在 /var/www 中,其中包含以下内容:
app
cake
.htaccess
index.php
vendors
The .htaccess file contains the following:
.htaccess 文件包含以下内容:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ /webroot/ [L]
RewriteRule (.*) /webroot/ [L]
</IfModule>
If I access my virtualhost (http://myhost/) I see the correct page. But even the JavaScript loaded with src="/js/validate.js"fails (it's located within /var/www/app/webroot/js/validate.js):
如果我访问我的虚拟主机 ( http://myhost/),我会看到正确的页面。但即使加载的 JavaScript 也src="/js/validate.js"失败(它位于 内/var/www/app/webroot/js/validate.js):
[Wed Aug 26 15:45:12 2009] [error] [client 10.7.10.52] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Wed Aug 26 15:45:12 2009] [debug] core.c(3063): [client 10.7.10.52] r->uri = /webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/webroot/webroot/webroot/webroot/webroot/js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/webroot/webroot/webroot/webroot/js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/webroot/webroot/webroot/js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/webroot/webroot/js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/webroot/js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] mod_deflate.c(632): [client 10.7.10.52] Zlib: Compressed 649 to 405 : URL /webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/js/prototype.js
Hence my question: what is the correct .htaccess required for CakePHP?
因此我的问题是:CakePHP 所需的正确 .htaccess 是什么?
Many, many thanks!
非常感谢!
回答by MrG
The answer is that there are 3 different .htaccess files:
答案是有 3 个不同的 .htaccess 文件:
/var/www/app/webroot/.htaccess
/var/www/app/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url= [QSA,L]
</IfModule>
/var/www/app/.htaccess
/var/www/app/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/ [L]
</IfModule>
/var/www/.htaccess
/var/www/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/ [L]
</IfModule>
It's been my fault, everything is listed on the CakePHP site. Thanks to everyone!
这是我的错,所有内容都列在CakePHP 站点上。谢谢大家!
回答by riotera
The correct .htaccess is the default:
正确的 .htaccess 是默认的:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/ [L]
</IfModule>
You have to add this in "/etc/apache2/sites-enabled/default":
您必须在“/etc/apache2/sites-enabled/default”中添加:
<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
if section already exists change AllowOverride None to AllowOverride All
如果部分已经存在,则将 AllowOverride None 更改为 AllowOverride All
回答by Kousalya
Removing .htaccess from main file may solve this problem. It worked for me(need not remove from webroot)
从主文件中删除 .htaccess 可能会解决这个问题。它对我有用(不需要从 webroot 中删除)
回答by MUY Belgium
If allowed by your provider you may put all in the httpd.conf file as follow
如果您的提供商允许,您可以将所有内容放入 httpd.conf 文件中,如下所示
<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/ [L]
</IfModule>
</Directory>
And so on for others directories...
等等其他目录...
回答by Ali Farhoudi
CakePHP has only one .htaccessfile inside webroot directory. No need more .htaccessfiles. You must set app/webrootas your DOCUMENT_ROOT.
CakePHP.htaccess在 webroot 目录下只有一个文件。不需要更多.htaccess文件。您必须设置app/webroot为您的DOCUMENT_ROOT.

