【问题标题】:htaccess rule is not working on localhosthtaccess 规则在本地主机上不起作用
【发布时间】:2012-08-17 13:06:41
【问题描述】:

抱歉,我更改了上一个问题。我在 localhost 上的 .htaccess 重写规则有问题,我在 http://localhost/testing/.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] 

请帮忙

谢谢:)

【问题讨论】:

  • 你确定你在你的 xampp 中激活了 mod_rewrite 吗?
  • 是的,我在 RewriteEngine on RewriteRule home index.php 上工作,它正在工作......在测试/主页上
  • 删除了 $ 符号,但仍然不起作用:P

标签: php html .htaccess url redirect


【解决方案1】:

您需要做的是通过执行以下步骤在您的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. 通过删除井号 (#) 标记取消注释该行。

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

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

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

【讨论】:

  • 已经取消注释了,我重启了XAMPP,但问题还是一样。谢谢你的回答。
  • 还没用,可能还有问题。也许我应该重新安装 XAMPP。
  • 您确定 .htaccess 文件在 testing 文件夹中并且您将代码更改为新的吗?
  • 是的,我确定它在测试文件夹中,它正是 .htaccess 我通过 commond 提示重命名了 htaccess.txt。
【解决方案2】:

我得到了适合我的解决方案。

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

谢谢大家:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-30
    • 1970-01-01
    • 2012-05-03
    • 2021-10-27
    • 1970-01-01
    • 2016-10-07
    • 1970-01-01
    相关资源
    最近更新 更多