htaccess的规则不工作在localhost(htaccess rule is not work

2019-09-21 11:15发布

对不起,我改变了以前的问题。 我有一个在本地主机上的.htaccess重写规则的问题,我在HTTP .htaccess文件://本地主机/测试/的.htaccess。 我想改变网址,如下所示

http://localhost/testing/site.php?site=test

http://localhost/testing/test

而我在.htaccess代码

RewriteEngine on
RewriteRule ^([^/\.]+)/?$ site.php?site=$1 [L]

这是工作正确的,但我也喜欢的网址

http://localhost/testing/pages.php?site=test&pid=2

这里pages.php有两个参数,网站名称和页面ID。 我想改写这个作为

http://localhost/testing/test/2

对于这两种情况我有一个不能正常工作波纹管代码

RewriteEngine on
RewriteRule ^([^/\.]+)/?$ site.php?site=$1 [L]
RewriteRule ^([^/\.]+)/?$ pages.php?site=$1&pid=$2 [L] 

请帮忙

谢谢 :)

Answer 1:

你需要做的是通过预成型这些步骤开启您的apecha服务器上的mod_rewrite的:

  1. 假设你解包的XAMPP的文件夹C:\目录下,导航到包含Apache的配置文件的文件夹。 完整路径是C:\xampp\apache\conf\.

  2. 在conf文件夹,你会发现一个名为httpd.conf文件。 这个文件包含所有的Apache的配置参数。 在文本编辑器中的文件。

  3. 搜索mod_rewrite.so,你会遇到如下一行: #LoadModule rewrite_module modules/mod_rewrite.so

  4. 通过移除井号(#)标记去掉注释。

  5. 保存文件并重新启动Apache Web服务器。

而且,如果该文件已经在testing文件夹中的代码应该是这样的:

RewriteEngine on
RewriteRule ^site\.html$ site.php?site_id=$1


Answer 2:

我的解决方案,为我工作。

RewriteEngine on
RewriteRule ^([^/\.]+)/?$ site.php?site=$1 [L]
RewriteRule ^([^/]+)/([^/\.]+)/?$ pages.php?site=$1&pid=$2 [L,QSA]

感谢大家 :)



文章来源: htaccess rule is not working on localhost