windows - RewriteRule 根本不在 .htaccess for Windows (Apache) 中写入

标签 windows apache .htaccess

问题

我正在使用 tutorial学习使用 Zend 框架。我无法通过“确保 .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 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]

最佳答案

  • 删除 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

关于windows - RewriteRule 根本不在 .htaccess for Windows (Apache) 中写入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16565522/

相关文章:

windows - VbScript,无需用户输入即可远程安装 exe?

Apache - 路径的某个组件缺少权限

apache - 使用 Apache Web 服务器进行 Http 实时流式传输

mysql - Debian,mysql : How can I tune these values

php - 菜鸟 URL 重写

php - 在主机上上传项目后禁止访问

c++ - 戈朗 : call Windows DLL functions

windows - 在 SFTP 批处理文件中包含密码

php - .htaccess 强制 'www.' 并将其余 url 正常附加到末尾

windows - Dos/Windows 批量插入符号在 set/P 提示符下转义