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.
精彩评论