Getting URL parameters with mod_rewrite
Here is my 开发者_如何学运维current rewrite rule
RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L]
RewriteRule ^post/([^/\.]+)/?$ index.php?post=$1 [L]
RewriteRule ^cat/([^/\.]+)/?$ index.php?cat=$1 [L]
three lines to do basically the same thing. Is there a way I can clean this up a bit? Is there one line that will accomplish this?
Also, Is there a way to pull multiple variables from a single url string? So if I had something like:
http://www.mysite.com?page=foo&id=123&color=red
how would I convert it to this:
http://www.mysite.com/page/foo/id/123/color/red
RewriteRule ^(cat|post|page)/([^/\.]+)/?$ index.php?$1=$2 [L]
because jacek_K
to you one part, I give you answer of second part :
to rewrite this URL(http://www.mysite.com/page/foo/id/123/color/red), use this:
RewriteRule ^page\/([^/\.]+)\/id\/(\d+)\/color\/([^/\.]+) index.php?page=$1&id=$2&color=$3 [L]
精彩评论