Mod_rewrite 和 $_GET 变量
如果我正在修改以下网址:
If I am mod_rewriting a URL from:
http://www.mysite.com/blog/这是我的标题/1/
到
http://www.mysite.com/blog.php?title=this-is-my-title&id=1
...之后是否可以随意将 get 值附加到 URL 上,或者 mod_rewrite 是否将其丢弃?
...is it possible then to arbitrarily attach a get value on to the URL later, or does the mod_rewrite throw it off?
我的重写规则:
RewriteRule ^blog/([A-Za-z]+)/(0-9]+)/? blog?title=$1&id=$2 [L]
示例:
我可以去吗http://www.mysite.com/blog/this-is-my-title/1/?first=Johnnie&last=Wiggles
这基本上意味着
http://www.mysite.com/blog.php?title=this-is-my-title&id=1&first=Johnnie&last=Wiggles
我认为这应该可行,但出于某种原因,目前不适合我.
I would think that should work, but for some reason it's not for me at the moment.
推荐答案
您可以将 QSA 添加到 RewriteRule
标志:
You can add QSA to the RewriteRule
flags:
RewriteRule page_([0-9]+).html page.php?id=$1 [QSA]
会将 page_1.html?a=2
重定向到 page.php?id=1&a=2
但是,要小心,因为请求 page_1.html?id=2
将重定向到 page.php?id=1&id=2
,并且(在 PHP 中), $_GET['id']
将是 2.
However, be careful because requesting page_1.html?id=2
will redirect to page.php?id=1&id=2
, and (in PHP), $_GET['id']
will be 2.
相关文章