【发布时间】:2014-02-25 10:56:00
【问题描述】:
Stack Overflow 生成重写 URL,
所以我需要知道如何像 Stack Overflow 一样做到这一点?
http://stackoverflow.com/questions/9168364/how-to-rewrite-seo-friendly-urls-like-stackoverflow => 200 ok.(without trailing slash)
http://stackoverflow.com/questions/9168364/how-to-rewrite-seo-friendly-urls-like-stackoverflow/ => 200 ok.(with trailing slash)
http://stackoverflow.com/questions/9168364/ => 301 redirect.
http://stackoverflow.com/questions/9168364 => 301 redirect.
我如何用 mod_rewrite 做到这一点?
我有这样的事情:
RewriteRule ^([0-9]+)[/]([^/]*) ./cat.php?id=$1&title=$2 [L,NC]
mydomain.com/999 => 404 not found.
mydomain.com/999/ => 200 ok.
mydomain.com/999/test => 200 ok.
mydomain.com/999/test/test2 => 200 ok.
mydomain.com/999/test/test2/test3 => 200 ok.
mydomain.com/999/test/test2/test3/test4 => 200 ok.
请告诉我如何更改 RewriteRule ?
【问题讨论】:
标签: php regex apache .htaccess mod-rewrite