开发者

regular expressions, modrewrite php apache

can any one see the problem with this?

the url is this normally:

page_test.php?page=latest_news&id=10518271191304876236

RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ page_test.php?开发者_如何学编程page=$1&id=$2

many thanks


There's no / in your URL, and your pattern is requiring one:

RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ page_test.php?page=$1&id=$2
                           ^---here

basically you're searching for:

one-or-more alpha-numerics separated by a / followed by one-or-more alphanumerics.


latest_news is not matched by [a-zA-Z0-9] because of the underscore _: you could use the word character class \w, which includes the underscore:

RewriteRule ^(\w+)/([a-zA-Z0-9]+)$ page_test.php?page=$1&id=$2

If the id is always numeric, you could shorten it even more using the number character class \d:

RewriteRule ^(\w+)/(\d+)$ page_test.php?page=$1&id=$2


RewriteRule ^([a-zA-Z0-9_]*)/([0-9]+)$ page_test.php?page=$1&id=$2

and you should be calling from:

www.yourdomain.com/latest_news/10518271191304876236
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜