Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 在WAMP 2.4上重写Mod__Apache_.htaccess_Mod Rewrite_Wamp - Fatal编程技术网

Apache 在WAMP 2.4上重写Mod_

Apache 在WAMP 2.4上重写Mod_,apache,.htaccess,mod-rewrite,wamp,Apache,.htaccess,Mod Rewrite,Wamp,我有WAMPServer2.4,我似乎无法让Mod_Rewrite在上面工作。我在Apache服务中启用了它,在httpd.conf中取消了mod_rewrite.so的注释,并重新启动了服务器。我还检查了我的phpinfo,它在services下列出了mod_rewrite 我正在测试它的站点位于地址localhost/eb/index.php后面,我试图在event.php页面上测试它,其中的url看起来像localhost/eb/event.php?id=1 这就是我的index.php文

我有WAMPServer2.4,我似乎无法让Mod_Rewrite在上面工作。我在Apache服务中启用了它,在httpd.conf中取消了mod_rewrite.so的注释,并重新启动了服务器。我还检查了我的phpinfo,它在services下列出了mod_rewrite

我正在测试它的站点位于地址localhost/eb/index.php后面,我试图在event.php页面上测试它,其中的url看起来像localhost/eb/event.php?id=1

这就是我的index.php文件所在的localhost/eb根目录中的my.htaccess文件的样子

<IfModule mod_rewrite.so>
RewriteEngine on
RewriteBase /eb/
RewriteRule ^event/([0-9]+)/?$event.php?id=$1
</IfModule>
即使在这之后,它仍然显示url localhost/eb/event.php?id=1

将RewriteBase/eb/添加到文档根目录而不是/eb/目录,并将所有重写添加到/eb/目录

更新

在您的http.conf上

<Directory *>            
   # changed from None to FileInfo
   AllowOverride FileInfo          
</Directory>
在文档根目录中添加RewriteBase/eb/而不是/eb/目录,并在/eb/目录中添加所有重写

更新

在您的http.conf上

<Directory *>            
   # changed from None to FileInfo
   AllowOverride FileInfo          
</Directory>

您还需要一个额外的外部重定向。保持.htaccess如下所示:

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /eb/

RewriteCond %{THE_REQUEST} /event\.php\?id=([^\s&]+) [NC]
RewriteRule ^ event/%1? [R=301,L]

RewriteRule ^event/([0-9]+)/?$ event.php?id=$1 [L,QSA]

您还需要一个额外的外部重定向。保持.htaccess如下所示:

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /eb/

RewriteCond %{THE_REQUEST} /event\.php\?id=([^\s&]+) [NC]
RewriteRule ^ event/%1? [R=301,L]

RewriteRule ^event/([0-9]+)/?$ event.php?id=$1 [L,QSA]

因此,在我的www根文件夹下,我在RewriteBase/eb/上添加了一个带有RewriteEngine的.htaccess文件,然后在eb文件夹下,我的.htaccess文件中的所有内容都作为OP,但不包括RewriteBase。在这些更改之后,mod_重写仍然不起作用:-/@ConnerBurnett请使用以下解决方案检查mod_重写:在_数组'mod_rewrite'中运行echo后,apache_get_模块从您给我的链接返回结果为1。我有一种感觉,它可能与Wamp有关。我应用了这些更改,但仍然没有结果。谢谢,这为我指明了正确的方向。我必须使用AllowOverride All使其工作。因此,在我的www根文件夹下,我在RewriteBase/eb/上添加了一个带有RewriteEngine的.htaccess文件,然后在eb文件夹下,我的.htaccess文件中的所有内容都作为OP,但不包括RewriteBase。在这些更改之后,mod_重写仍然不起作用:-/@ConnerBurnett请使用以下解决方案检查mod_重写:在_数组'mod_rewrite'中运行echo后,apache_get_模块从您给我的链接返回结果为1。我有一种感觉,它可能与Wamp有关。我应用了这些更改,但仍然没有结果。谢谢,这为我指明了正确的方向。我不得不使用AllowOverride来让它工作。它工作了!请你解释一下为什么会有这么多规则好吗?我读过的所有教程都只展示了如何使用OP中的重写规则。另外,我现在需要做什么才能使我的CSS脚本在已重写的页面上工作?这是一个动态页面,因此css调用位于header.php中,该文件包含在其他页面文件中。对于css/js问题,请在css、js、图像文件中使用绝对路径,而不是相对路径。这意味着您必须确保这些文件的路径以http://或斜杠开头。或者您可以尝试在页面标题中添加此项:此处需要2条规则。规则1:将实际/eb/event.php?id=123重定向到/eb/event/123,并将第二个规则内部重写/eb/event/123 URI到实际的/eb/event.php?id=123。成功了!请你解释一下为什么会有这么多规则好吗?我读过的所有教程都只展示了如何使用OP中的重写规则。另外,我现在需要做什么才能使我的CSS脚本在已重写的页面上工作?这是一个动态页面,因此css调用位于header.php中,该文件包含在其他页面文件中。对于css/js问题,请在css、js、图像文件中使用绝对路径,而不是相对路径。这意味着您必须确保这些文件的路径以http://或斜杠开头。或者您可以尝试在页面标题中添加此项:此处需要2条规则。规则1:将实际/eb/event.php?id=123重定向到/eb/event/123,并将第二个规则内部重写/eb/event/123 URI到实际的/eb/event.php?id=123。