我想不出一个好的标题,这很难解释.基本上,我的服务器上有 mod_rewrite 设置.它将每个 ?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/
我想实现一个功能,我可以这样做:/login/?return_url=/home/
return_url 将根据用户上次所在的位置而变化.我知道还有其他方法可以找出返回 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.
我的问题是以下内容不起作用:/login/?return_url=/home/
My issue is that the following does not work: /login/?return_url=/home/
但是,/login.php?return_url=/home/
确实有效.
为什么 PHP 在第一种(首选)情况下看不到 return_url
变量?
Why can't PHP see the return_url
variable in the first (preferred) situation?
这是我当前的代码:
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'
(查询字符串追加)
此标志强制重写引擎将替换字符串的查询字符串部分附加到现有的字符串,而不是替换它.当你想要的时候使用这个通过重写规则向查询字符串添加更多数据.
'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]
会让 something/9?key=val
转到 something.php?id=9&key=val
这篇关于当不遵守规则时,Mod 重写并使用 PHP 的 GET 获取 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!