用 .htaccess 重写 url
我需要重写一个像 test.php?type=$1&val=$2 这样的 url type 始终是字符串,其中 val 可以是数字或字符串。我想出了以下内容 test/([a-zA-Z]+)/([a-zA-Z0-9|]+)/([0-9]+).html
但正如预期的那样不适用于类似 test/hello-world/23.html
我如何在表达式中包含破折号?
I need to rewrite a url like test.php?type=$1&val=$2
type will always be a string where as val could be a number or a string. I came up with the followingtest/([a-zA-Z]+)/([a-zA-Z0-9|]+)/([0-9]+).html
but as it was expected it will not work with something lke test/hello-world/23.html
How can i included dashes in the expression?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以逃脱他们,所以如果你有
You can escape them, so if you had
对我来说,这更像是一个关于正则表达式的问题。
test/([a-zA-Z-]+)/([a-zA-Z0-9|-]+)/([0-9]+).html
应该可以。将破折号放在字符类的末尾非常重要。This seems more like a question about regular expressions to me.
test/([a-zA-Z-]+)/([a-zA-Z0-9|-]+)/([0-9]+).html
should do. It's important to put the dash at the end of the character class.