且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

国防部重写和使用PHP的获取URL的当不遵守规则

更新时间:2023-02-24 10:18:40

的的 QSA 指令可能是你要找的是什么:

  

qsappend | QSA'(查询字符串追加)
   此标记强制重写   发动机追加替换字符串到的查询字​​符串的一部分   现有的字符串,而不是取代它。当你想用这种   通过重写规则添加更多的数据的查询字符串。

例如,

 重写规则^东西/([0-9] +)$ something.php?ID = $ 1 [QSA]
 

会让的东西/ 9键= VAL something.php ID = 9和;?关键= VAL

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/

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.

My issue is that the following does not work: /login/?return_url=/home/

However, /login.php?return_url=/home/ does work.

Why can't PHP see the return_url variable in the first (preferred) situation?

Here's my current code:

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]

The QSA directive is probably what you're looking for:

'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.

E.g.,

RewriteRule ^something/([0-9]+)$ something.php?id=$1 [QSA]

Will let something/9?key=val go to something.php?id=9&key=val