【问题标题】:htaccess: Why doesn't this work?htaccess:为什么这不起作用?
【发布时间】:2009-06-25 18:41:39
【问题描述】:

当我在 htaccess 中尝试以下规则时,我得到一个 404 错误页面:

RewriteRule ^Test\?service=(.*) test.php?foo=$1 [NC,L]

怎么会?

我知道最好使用 ^Test/(.*) test.php?foo=$1 [NC,L] 之类的东西,但在这种情况下,我更喜欢它就像我说的那样。

提前谢谢你。

【问题讨论】:

  • 您在浏览器中输入了什么地址?我希望它与您的正则表达式不匹配。

标签: .htaccess mod-rewrite


【解决方案1】:

RewriteRule 只检查URL path。但是查询(从第一个 ? 到第一个 # 的部分)不是 URL 路径的一部分。这只能通过RewriteCond directive 进行检查:

RewriteCond %{QUERY_STRING} ^service=(.*)
RewriteRule ^Test$ test.php?foo=%1 [NC,L]

【讨论】:

  • 对了,如何追加多个参数?
  • @Ivarska:你能举个例子吗?
  • @Gumbo: ex: Test?x=foo&y=bar >>> qwe.php?a=Test&b=foo&c=bar
  • 设置 QSA 标志并将原始查询附加到新查询。
猜你喜欢
  • 2014-10-24
  • 1970-01-01
  • 2017-06-12
  • 1970-01-01
  • 2012-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-17
相关资源
最近更新 更多