【问题标题】:Rewrite rule in Apache/htaccess doesn't workApache/htaccess 中的重写规则不起作用
【发布时间】:2012-03-26 10:13:34
【问题描述】:

这是我的 htaccess 文件中的内容,该文件与我的 php 项目位于同一目录中:

Options +FollowSymLinks
Options +Indexes
RewriteEngine On

RewriteBase /

我的页面上有一个链接可以将用户发送到这个地址:

http://localhost/PHPTest/index.php?article=27

这是我想要的输出== index.php/article_27 ?

更新:

当我点击链接时,这是 url 中的输出:

http://localhost/PHPTest/index.php?article=27

这个应该在我的php项目文件夹中的.htaccess中截取并换成这个:

 http://localhost/PHPTest/index.php/article_id_27

这是我的重写规则。但它不起作用:

RewriteRule ^index.php?article=([0-9]+)$ index.php/article_id_$1 

更多信息。有我的项目路径,其中index php是:

C:\xampp\htdocs\PHPTest

【问题讨论】:

  • RewriteRule 的参数不是倒序吗? the server doesn't produce this 是什么意思?
  • 它不起作用/////////
  • 我不能说您的评论更能说明您面临的问题。更清楚您想要实现的目标以及目前正在发生的事情。
  • 网址不显示为 index.php/article_27.. 如答案中所述
  • 您的新规则将不起作用 -- 查询字符串无法与 RewriteRule 匹配。对于查询字符串,请使用 RewriteCond %{QUERY_STRING} PATTERN_HERE,然后使用 %1 而不是 $1 引用它(查看 mod_rewrite 文档:httpd.apache.org/docs/current/mod/mod_rewrite.html)。

标签: apache .htaccess


【解决方案1】:

网址不显示为 index.php/article_27

为什么会这样?您将链接指向 ...article=27 并且您的规则将 from ...article_27 to ...article=27 重写。

在您给出的场景中,您可能想要从...article=27...article_27重定向,而不是重写。

【讨论】:

  • 我想使用这种模式:RewriteRule ^oldfile\.html newfile.html // 这基本上就是我想要的...查看更新
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多