Mod_rewrite 和 $_GET 变量 [英] Mod_rewrite and $_GET variables

查看:27
本文介绍了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.

这篇关于Mod_rewrite 和 $_GET 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆