【发布时间】:2011-08-30 00:54:27
【问题描述】:
我有一个 Zend Framework 应用程序,在根目录中有一个 .htaccess 文件,将所有流量定向到 /public 目录,index.php 所在的目录。
这是.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]
如您所见,有两行注释掉了。
该部分据称将流量定向到 /public,并且在我的本地服务器和共享主机上运行,但在我的客户端服务器上似乎失败了。
因此,将两行注释掉后,当我在浏览器中键入站点地址时,我会得到一个目录列表。当我将/public 附加到地址时,正如预期的那样,我被带到/public/index.php,但由于请求没有正确重定向,所以也不是 JS 和 CSS 文件。
当我取消注释这些行时,我收到 500 内部服务器错误(根本没有达到index.php)。
其他重写工作正常(至少据我所知)。
任何想法为什么会发生这种情况以及如何纠正这个问题?
提前致谢。
【问题讨论】:
-
据我所知,“#”是配置(或 .htaccess)文件中唯一允许的注释字符,因此您的两个“注释”行实际上不是。来自Apache Server 2.x documentation:
Lines that begin with the hash character "#" are considered comments, and are ignored. Comments may not be included on a line after a configuration directive. -
感谢您的评论。我实际上删除了“注释掉:我的 .htaccess 中的行,并且只将它们留在这里以供参考关于删除的内容。我不知道分号是无效的注释字符;)。
标签: .htaccess zend-framework internal-server-error