.htaccess RewriteRule 帮助
以下网址的重写规则是什么
mysite.com/001234-some-keywords.html
我想捕获 6 位参考号,例如 ([0-9]{6})
我的索引文件是
templates/default/index.php?ref=001234
有一天我做了一个正则表达式速成课程..我保证。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能
([0-9]{6})
已经是正确的,它捕获六位数字.*
匹配之后的任何字符。$1
被第一个捕获组()
的内容替换如果您想限制 URL 仅在恰好有六位数字时匹配,那么它应该如下所示(注意破折号
-
):或仅在以
.html
结尾时匹配 URL:我建议阅读
mod_rewrite
文档。regular-expressions.info 也非常适合学习正则表达式。
Probably
([0-9]{6})
was already correct, it captures the six digits.*
matches any character afterwards.$1
gets replaced by the contents of the first capture group()
If you want to restrict the URL to match only if there are exactly six digits, then it should look like this (note the dash
-
):or matching the URL only if it is ending in
.html
:I suggest to read the
mod_rewrite
documentation.Also regular-expressions.info is great for learning regular expressions.