htaccess规则在localhost上不起作用


htaccess rule is not working on localhost

对不起,我更改了前面的问题。我对localhost上的.htaccess重写规则有问题,我在http://localhost/testing/.htaccess。我想更改如下的url

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

http://localhost/testing/test

我在.htaccess中有代码作为

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

这是正确的工作,但我也有类似的url

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] 

请帮助

感谢:)

您需要执行以下步骤来打开Apache服务器上的mod_rewrite

  1. 假设您已经解压缩了C:'目录中的xampp文件夹,请导航到包含apache配置文件的文件夹。完整路径为C:'xampp'apache'conf'.

  2. 在conf文件夹中,您会发现一个名为httpd.conf的文件。这个文件保存了apache的所有配置参数。在文本编辑器中打开文件。

  3. 搜索mod_rewrite.so,您会看到一条线,如下所示:#LoadModule rewrite_module modules/mod_rewrite.so

  4. 通过删除hash(#)标记来取消对该行的注释。

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

此外,如果文件已经在testing文件夹中,您的代码应该如下所示:

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

我得到了对我有效的解决方案。

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

感谢大家:)