我正在尝试使用Apache24 server mod_rewrite模块,但我无法加载它。 我知道有很多关于这个话题的问题,我经历了所有这些,但似乎没有任何工作。 这些是我一直沿用的步骤—
CHANGED httpd.conf文件进行了这些更改:
一个。 LoadModule rewrite_module modules/mod_rewrite.so
湾 将AllowOverride None更改为AllowOverride All
重新启动Apache服务器
使用命令提示符命令httpd -M检查加载的模块。 我可以看到那里的mod_rewrite模块已经加载。 我附上下面的图片。
但执行所有这些步骤后,我看不到mod_rewrite作为加载模块在phpinfo 。
如上图所示,没有装载mod_rewrite模块。 另外作为一个狂野的黑客,我甚至尝试使用.htaccess文件重写url,但这是行不通的。 Apache似乎忽略了.htaccess文件,尽pipe我把这个文件放在我的根目录下。
Note: I am running `PHP` as an apache module Using `WAMP` stack Using `localhost` as server
我需要这个模块严重的URL重写的目的。 你们可以build议一些其他的方式来加载这个模块?
编辑
我试图从虚拟主机重写URL,因为答案表明模块已加载,它不依赖于.htaccess和info.php 。但stil不是redirect。 我在下面添加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时,上面的代码不会redirect到working.php 。 它只是说:
在此服务器上找不到请求的URL /working.php。
除了加载模块,您需要的唯一指令是:
重写引擎
额外:
从你的链接截图中,你的服务器根目录(文件系统path)看起来是C:/Apache24 ,但是你在任何服务器configuration指令中都没有引用C: 您需要引用完整的文件系统path,例如:
<Directory "C:/Apache24/htdocs">
RewriteRule ^working.php fun.html
该指令直接在VirtualHost( <Directory>容器之外)中使用,将永远不匹配。 当在VirtualHost(或服务器configuration)上下文中使用时,mod_rewrite匹配完整的URLpath,其中特别包括斜线前缀。 这与使用mod_rewrite是一个目录/ .htaccess上下文(当不包括斜杠前缀时)是一个重要的区别。