问题
我正在使用tutorial来学习使用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。就这样。
这是事情,它不是重写请求AT ALL,给我一个404未找到的错误,我理解,因为它正在寻找一个“fileDoesntExist”(显然不存在)。当我查看该虚拟主机的错误日志时,Get post是GET / fileDoesntExist ...这是错误的,因为它应该是GET /index.php,因为RewriteRule放在.htaccess中。
环境
Windows 8 Apache 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”(垃圾)我得到一个“内部服务器错误”。
我不知道会出现什么问题,非常感谢帮助,因为花时间配置而非开发是非常令人沮丧的。
根据De Morgan的法律,我试图调整.htaccess的内容,以便它只关心何时找不到请求的页面。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-l
Rewritecond %{REQUEST_FILENAME} !-d
Rewritecond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ index.php [NC,L]
答案 0 :(得分:2)
AccessFilename
指令(默认使用.htaccess
)将<Directory>
更改为(删除所有混乱)
<Directory "C:/Apache24/hosts/zf2-tutorial/public"> <!-- forward slashes -->
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny <!-- Fix your order (allow first) -->
Allow from all
</Directory>
确保.htaccess
位于DocumentRoot