問(wèn)題描述
我想不出一個(gè)好的標(biāo)題,這很難解釋.基本上,我的服務(wù)器上有 mod_rewrite 設(shè)置.它將每個(gè) ?a=1&b=2&c=3 etc 變成/1/2/3/
I couldn't think of a good title for this, it's hard to explain.
Basically, I have mod_rewrite setup on my server. It turns each ?a=1&b=2&c=3 etc into /1/2/3/
我想實(shí)現(xiàn)一個(gè)功能,我可以這樣做:/login/?return_url=/home/
return_url 將根據(jù)用戶上次所在的位置而變化.我知道還有其他方法可以找出返回 url,但我想將其保留在 URL 中.
I want to implement a feature where I can do something like this: /login/?return_url=/home/
The return_url would change depending on where the user was last. I know there are other methods of finding out the return url, but I would like to keep it in the URL.
我的問(wèn)題是以下內(nèi)容不起作用:/login/?return_url=/home/
My issue is that the following does not work: /login/?return_url=/home/
但是,/login.php?return_url=/home/
確實(shí)有效.
為什么 PHP 在第一種(首選)情況下看不到 return_url
變量?
Why can't PHP see the return_url
variable in the first (preferred) situation?
這是我當(dāng)前的代碼:
RewriteRule ^(.*)/(.*)/(.*)/([A-Za-z0-9_-]+)/$ /?a=$1&b=$2&c=$3&d=$4 [L]
RewriteRule ^(.*)/(.*)/([A-Za-z0-9_-]+)/$ /?a=$1&b=$2&c=$3 [L]
RewriteRule ^(.*)/([A-Za-z0-9_-]+)/$ /?a=$1&b=$2 [L]
RewriteRule ^([A-Za-z0-9_-]+)/$ /?a=$1 [L]
推薦答案
QSA
指令 可能就是你要找的:
The QSA
directive is probably what you're looking for:
'qsappend|QSA'
(查詢字符串追加)
此標(biāo)志強(qiáng)制重寫引擎將替換字符串的查詢字符串部分附加到現(xiàn)有的字符串,而不是替換它.當(dāng)你想要的時(shí)候使用這個(gè)通過(guò)重寫規(guī)則向查詢字符串添加更多數(shù)據(jù).
'qsappend|QSA'
(query string append)
This flag forces the rewrite engine to append a query string part of the substitution string to the existing string, instead of replacing it. Use this when you want to add more data to the query string via a rewrite rule.
例如,
RewriteRule ^something/([0-9]+)$ something.php?id=$1 [QSA]
會(huì)讓 something/9?key=val
轉(zhuǎn)到 something.php?id=9&key=val
這篇關(guān)于當(dāng)不遵守規(guī)則時(shí),Mod 重寫并使用 PHP 的 GET 獲取 URL的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!