无法加载mod_rewrite Apache模块

时间:2017-01-21 14:25:20

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

我正在尝试使用mod_rewrite的{​​{1}}模块,但我无法加载它。我知道有很多关于这个主题的问题,我已经完成了所有这些问题,但似乎没有任何工作。这些是我到目前为止所遵循的步骤---

  1. 已更改Apache24 server文件进行了这些更改 -
  2. 一个。取消注释httpd.conf

    湾已将LoadModule rewrite_module modules/mod_rewrite.so更改为AllowOverride None

    1. 重新启动的apache服务器

    2. 使用命令提示符命令AllowOverride All检查已加载的模块。我可以看到mod_rewrite模块已加载。我附上下面的图片。 enter image description here

    3. 但在执行所有这些步骤后,我无法在httpd -M中看到mod_rewrite为已加载的模块。 enter image description here 从上面的图片可以看出,没有mod_rewrite加载模块。 另外,作为一个疯狂的黑客,我甚至尝试使用phpinfo文件重写URL,但这不起作用。 Apache似乎忽略了.htaccess文件,尽管我已将该文件放在我的根目录中。

      .htaccess

      我需要这个模块才能进行URL重写。你们可以建议其他方法加载这个模块吗?

      过去两天,我正在开玩笑。您是否认为需要重新安装或者它与路径依赖性有关。任何建议将不胜感激。

      修改

      我试图从虚拟主机重写URL,因为答案表明模块已加载,并且它既不依赖于 Note: I am running `PHP` as an apache module Using `WAMP` stack Using `localhost` as server 也不依赖.htaccess。但是它不是重定向的。我在下面添加info.php设置---

      Virtual host

      当我尝试运行fun.html时,上面的代码没有将其重定向到working.php。它只是说<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> 。 提前谢谢!

1 个答案:

答案 0 :(得分:1)

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

如果你真的需要使用mod_rewrite,只需确保在其他重写指令之前添加RewriteEngine on

注意:我确实需要mod_rewrite知道我接下来需要配置什么,在很多情况下它没有必要和过度使用。

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