问题
我正在使用教程来学习使用 Zend Framework。我无法通过“确保 .htaccess 正常工作”部分。我知道有很多关于 Windows 的问题,我会提到我所做的,以便我们可以在同一页面上。
.htaccess 的内容如下:
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [NC,L]
简而言之,当我键入 url\fileDoesntExist 时, .htaccess 规则应该捕获并将其转换为 index.php 。就这样。
事情是这样的,它根本没有重写请求,给了我一个 404 not found 错误,我理解这是因为它正在寻找“fileDoesntExist”(显然不存在)。当我查看该虚拟主机的错误日志时,Get 帖子是 GET /fileDoesntExist ...这是错误的,因为它应该是 GET /index.php,因为 RewriteRule 放置在 .htaccess 中。
环境
视窗 8 阿帕奇 2.4
httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so --> UNCOMMENTED
AccessFilename htaccess --> (some have said that for Windows, it should be placed without the
leading dot)
<Directory "C:\Apache24\hosts\zf2-tutorial\public">
DirectoryIndex index.php
AllowOverride all
Order Deny,Allow
Allow from all
Options Indexes FollowSymLinks
Require all granted
RewriteRule ^(.*)$ index.php [NC,L] --> one user said that in windows if the rewriteRule is
not placed here, then it won´t take place.
</Directory>
想法尝试无济于事
通过 phpinfo(); 我可以看到 rewrite_module 实际上已加载。如果我删除 .htaccess 中的内容并放入类似“aksdhfñashfña”(垃圾)的内容,我会收到“内部服务器错误”。
我不知道可能是什么问题,非常感谢您的帮助,因为花时间进行配置而不是开发非常令人沮丧。
遵循德摩根定律,我尝试调整 .htaccess 的内容,以便它只在找不到请求的页面时才关心。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-l
Rewritecond %{REQUEST_FILENAME} !-d
Rewritecond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ index.php [NC,L]