重写URL规则,例如StackOverflow

时间:2011-03-22 22:19:53

标签: php apache

从这个网址中提取id号码(434376)的apache重写网址是什么?

http://stackoverflow.com/questions/434376/unique-url-slug

类似

RewriteEngine On  
RewriteRule ^questions/([0-9]+)/?$([A-Za-z0-9-]+)   post.php?post_id=$1 [NC,L]  

...但它在我的网站上无效...任何提示?

感谢

2 个答案:

答案 0 :(得分:1)

测试:

RewriteRule ^questions/([0-9]+)/?.*$   rewrite.php?post_id=$1 [NC,L]

答案 1 :(得分:0)

如果/是可选的,它应该是:

RewriteRule ^questions/([0-9]+)/?([A-Za-z0-9-]+)?/?$   post.php?post_id=$1 [NC,L]

让我知道它是否有效..

相关问题