开发者

What regular expression can I use to pass GET variables via URL rewrite?

开发者 https://www.devze.com 2023-02-12 03:21 出处:网络
I know that I should pass variables through the structure of the url instead of passing them via GET, but I find myself in this situation where I already have a fixed URL structure, and I need to pass

I know that I should pass variables through the structure of the url instead of passing them via GET, but I find myself in this situation where I already have a fixed URL structure, and I need to pass additional parameters that are needed only in certain particular cases, so are not always present in the request. Since regexp's are one of my weak points, I could use some help.. What I have is:

categories/10/category name.html?开发者_JAVA技巧somevar=X&someothervar=Y

what I would need is:

RewriteRule ^categories/([0-9]+)/([^/]+).htmlwhat should I put here?$ somepage.php?section=cat&id=$1&name=$2&somevar=$3&someothervar=$4


If you only need them in certain cases, don't rewrite them, but use the QSA modifier (Query String Append), which will let you keep the additional query string stuff.

Like:

RewriteRule ^categories/([0-9]+)/([^/]+).html$ somepage.php?section=cat&id=$1&name=$2 [QSA]

Using this, if categories/10/categoryname.html?somevar=X&someothervar=Y is requested, you will get the rewritten query vars as well as the additional ones in your app.

0

精彩评论

暂无评论...
验证码 换一张
取 消