![](/img/trans.png)
[英]htaccess rewriterule windows/linux , domain to subpage
[英]RewriteRule not writing at all in .htaccess for Windows (Apache)
问题
我正在使用教程来学习使用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 ...这是错误的,因为由于.htaccess中放置了RewriteRule,因此它应该是GET /index.php。
环境
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]
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.