【问题标题】:Cannot load mod_rewrite Apache module无法加载 mod_rewrite Apache 模块
【发布时间】:2017-06-06 10:28:32
【问题描述】:

我正在尝试使用Apache24 servermod_rewrite 模块,但我无法加载它。我知道有很多关于这个话题的问题,我已经解决了所有问题,但似乎没有任何效果。这些是我到目前为止所遵循的步骤---

  1. CHANGED httpd.conf 文件进行了这些更改--

一个。取消注释LoadModule rewrite_module modules/mod_rewrite.so

b.将AllowOverride None 更改为AllowOverride All

  1. 重启apache服务器

  2. 使用命令提示符命令httpd -M 检查加载的模块。我可以在那里看到 mod_rewrite 模块已加载。我附上下面的图片。

但在执行完所有这些步骤后,我无法在 phpinfo 中看到 mod_rewrite 作为已加载模块。 如上图所示,没有加载 mod_rewrite 模块。 同样作为一个疯狂的黑客,我什至尝试使用.htaccess 文件重写 URL,但这不起作用。 Apache 似乎忽略了 .htaccess 文件,尽管我已将该文件放在我的根目录中。

 Note: I am running `PHP` as an apache module
 Using `WAMP` stack
 Using `localhost` as server

我非常需要这个模块来重写 URL。你们能建议一些其他方式来加载这个模块吗?

在过去的两天里,我一直在头疼。您认为需要重新安装还是与路径依赖性有关。任何建议将不胜感激。

编辑

我试图从虚拟主机重写 URL,因为答案表明模块已加载,它既不依赖于 .htaccess 也不依赖于 info.php。但它仍然没有重定向。我在下面添加Virtual host 设置---

<VirtualHost *:80>
<Directory "/Apache24/htdocs">
Options FollowSymLinks 
AllowOverride All
DirectoryIndex index.html index.php
</Directory>
ServerName localhost
DocumentRoot "/Apache24/htdocs"
ErrorLog "/Apache24/logs/error.log"
CustomLog "/Apache24/logs/access.log" combined
<directory "/Apache24/htdocs">

    <IfModule rewrite_module>
            Options +FollowSymlinks
            RewriteEngine On
    </IfModule>

    <IfModule rewrite_module>
            RewriteRule   ^working.php   fun.html
    </IfModule>

</directory>
# Rewrite Rules #####################
RewriteEngine On
RewriteRule   ^working.php   fun.html
# end Rewrite Rules #################   
</VirtualHost>

当我尝试运行 fun.html 时,上面的代码不会将其重定向到 working.php。它只是说the requested URL /working.php was not found on this server.。 提前致谢!

【问题讨论】:

  • error.log 中是否有任何错误?
  • 错误日志中没有错误。

标签: php apache .htaccess mod-rewrite httpd.conf


【解决方案1】:

如果 apachectl -M 或 httpd -M 表示模块已加载,则已加载。 phpinfo 是一个外部的东西,由一个 php 脚本运行,你为什么要信任它而不是 httpd 自己的软件?

如果您确实需要使用 mod_rewrite,请确保在其他重写指令之前添加 RewriteEngine on

注意:我真的会确保我需要 mod_rewrite 知道我接下来必须配置什么,在许多情况下它没有必要并且被过度使用。

非常重要:要配置你的服务器,如果是你的服务器 你不需要.htaccess,mod_rewrite也不依赖它

【讨论】:

  • 我正在尝试从虚拟主机重写 url 但它不起作用.. 但我的 mod_rewrite 模块已加载到 apache 中。
  • 如何“它不工作”,它不工作几乎没有说明调试它的任何价值。您请求哪个 uri,您希望发生什么,会发生什么?你有没有激活rewritelog 看看?等
  • 我已经修改了我的问题,请看一下。重写日志没有错误。
  • 运行良好,感谢您的宝贵意见..使用虚拟主机。
  • 很高兴你把它整理出来@neophyte
猜你喜欢
  • 1970-01-01
  • 2021-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-09
  • 1970-01-01
相关资源
最近更新 更多