正则表达式的.htaccess重写规则 [英] .htaccess regex rewrite rule
本文介绍了正则表达式的.htaccess重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的正则表达式:
I have the following regex:
RewriteRule ^blogs/([^/]*)/([^/]*) blogs/index.php?blogger=$1&blog=$2
这工作正常以下情况:
- http://myurl.com/blogs/blog-name/blog-article /
- http://myurl.com/blogs/blog-name/blog-article
- http://myurl.com/blogs/blog-name/ 李>
- http://myurl.com/blogs/blog-name/blog-article/
- http://myurl.com/blogs/blog-name/blog-article
- http://myurl.com/blogs/blog-name/
但它不处理:
我怎样才能使/分隔符可选在这个正则表达式?
How can I make the "/" separator optional in this regex?
推荐答案
我会使用:
^blogs/([^/]*)(/([^/]*))?
和你只需要检查,确保 $ 2
仍然是正确的(与两个捕获组,它可能是 $ 3
......我不记得了)。
And you'd just have to check and make sure that $2
is still correct (with the two capture groups, it might be $3
… I can't remember).
这篇关于正则表达式的.htaccess重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文