htaccess的导致服务器错误500 [英] htaccess causing server error 500
问题描述
我在根目录下的的.htaccess
文件Zend框架应用程序,指挥所有的流量到 /公共
目录,其中的index.php
所在。
I have a Zend Framework application with a .htaccess
file in the root directory, directing all traffic to the /public
directory, where index.php
resides.
这是内容的的.htaccess
:
RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/(upload|img|js|css|less)/.*$
RewriteCond %{DOCUMENT_ROOT}/public/upload%{REQUEST_URI} -f
RewriteRule ^(.+\.(jpg|png|mp3))$ /public/upload%{REQUEST_URI} [NC,L]
;RewriteCond %{REQUEST_URI} !^/public/.*$
;RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]
正如你所看到的,有两个注释行。
As you can see, there are two commented out lines.
本节,据说指挥交通,以 /公共
,并工作在我的本地服务器和我共享的主机,似乎惨败我的客户的服务器上。
The section, supposedly directing traffic to /public
, and which works on my local servers and my shared host, seems to fail miserably on my client's server.
所以,用两行注释掉,当我输入网站的地址,在浏览器中,我得到一个目录列表。当我追加 /公共
的地址,我采取了 /public/index.php
,符合市场预期,但由于该请求没有被正确定向,也不是对JS和CSS文件的那些。
So, with the two lines commented out, when I type the site's address in the browser, I get a directory listing. When I append /public
to the address, I'm taken to /public/index.php
, as expected, but since the request wasn't redirected correctly, neither are the ones to the JS and CSS files.
当我去掉了线,我得到一个500内部服务器错误(的index.php
都达不到)。
When I uncomment the lines, I get a 500 internal server error (index.php
is not reached at all).
另外重写正常工作(至少据我可以告诉)。
The other rewrites work correctly (at least as far as I can tell).
任何想法,为什么会发生这种情况,以及如何纠正呢?
Any ideas why this would happen and how to correct this?
在此先感谢。
推荐答案
保存自己很多痛苦的和做到以下几点:
Save yourself a lot of grief and do the following:
- 文档根目录设置为
公开
目录。 - 将<一href="http://framework.zend.com/manual/en/project-structure.rewrite.html#project-structure.rewrite.apache.vhost"相对=nofollow>改写在虚拟主机条目规则或使用标准的<一个href="http://framework.zend.com/manual/en/project-structure.rewrite.html#project-structure.rewrite.apache.htaccess"相对=nofollow> Zend框架重写规则的在
公开
目录的.htaccess
文件。
- Set the document root to the
public
directory. - Set the rewrite rules in the VirtualHost entry or use the standard Zend Framework rewrite rules in a
.htaccess
file in thepublic
directory.
好了,给你的共享主机的限制,试试这个......
Ok, given your shared hosting constraints, try this one out...
- 将所有的
公开
文件到您的文档根目录,包括上述第2步中提到的的.htaccess
文件 - 将文件夹中的其余部分(即
应用程序
,库
)在文件系统中的任何地方,preferably外的Web文档根目录。一个例子可能是/家庭/用户/应用程序/我的-APP-名称/
-
修改
的index.php
与文件中的新APPLICATION_PATH
,例如:
- Place all the
public
files into your document root including the.htaccess
file mentioned in step #2 above - Place the rest of the folders (ie
application
,library
) anywhere in the filesystem, preferably outside the web document root. An example might be/home/user/apps/my-app-name/
Modify the
index.php
file with the newAPPLICATION_PATH
, eg
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', 'home/user/apps/my-app-name/application');
现在一切都应该只是工作,你的网站将不会与在URL中的公共一词访问。
Now everything should "just work" and your site won't be accessed with the word "public" in the URL.
这篇关于htaccess的导致服务器错误500的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!