htaccess Mod将$ _GET重写为普通URL

时间:2013-12-20 09:06:39

标签: .htaccess

我有这个重写规则:

RewriteRule ^([a-zA-Z0-9-]+)/([0-9]+)/?$ /home.php?id=$1&slug=$2 [L,QSA]

目前正在重写像home.php这样的内容?id = blog& slug = 123 to be blog / 123

如何更改它以便123是文本和数字而不仅仅是数字?

我在我的htaccess文件中有重定向:

home.php?id=services to /services

我也希望能够:

home.php?id=blog&slug=slug-goes-here to be /blog/slug-goes-here

1 个答案:

答案 0 :(得分:0)

[0-9]+部分替换为[\w-]+。这将匹配字符0-9,a-z,A-Z,_(下划线)和 - (连字符):

RewriteRule ^([a-zA-Z0-9-]+)/([\w-]+)/?$ /home.php?id=$1&slug=$2 [L,QSA]

此外,您可能希望阅读有关正则表达式基础知识的内容:http://www.regular-expressions.info/

相关问题