【问题标题】:Mod Rewrite - Regular Expression to include everything but slashMod Rewrite - 正则表达式包含除斜杠之外的所有内容
【发布时间】:2013-01-12 12:38:41
【问题描述】:

在我的 .htaccess 中,我有一个重写规则,它从一个干净的 url 读取 $_GET 值。对于 url 中的一个部分,我允许所有字符 (.*) 成为 var 的一部分。唯一的问题是当我从 twitter 访问我的网站的链接时,它在 url 中包含一个最终的“/”。

RewriteRule ^advertise/([A-Za-z0-9]+)/(.*)/?$ advertise/?a=b&content=$1&content_att=$2 [L]

www.mysite.com/advertise/content/content_att 工作得很好
- 但是
www.mysite.com/advertise/content/content_att/ 尝试将“/”作为 content_att 变量的一部分。只排除斜线的表达式是什么? (或任何其他 mod_rewrite 约定来完成此操作)

【问题讨论】:

  • 已编辑 - 那些是斜杠 / 不是反斜杠 \
  • 感谢您的纠正。

标签: php mod-rewrite


【解决方案1】:

[^/] 将包含除/ 之外的任何字符
[^/]* 将包含除/ 之外的任意数量的字符

实际效果应该是这样的:

RewriteRule ^advertise/([A-Za-z0-9]+)/([^/]+)/?$ advertise/?a=b&content=$1&content_att=$2 [L]

【讨论】:

  • 你是对的。应该是+。我看到您的答案基本相同,只是在我之前。所以,用整个重写规则更新你的答案,我会删除我的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-10
  • 2017-05-22
  • 1970-01-01
  • 2018-09-21
  • 1970-01-01
相关资源
最近更新 更多