在RewriteRule期间将原始url添加为标头或查询参数 [英] Adding the original url as header or query parameter during RewriteRule
问题描述
我正在寻找一种在RewriteRule期间获取原始URL并将其作为附加参数附加到查询字符串或将其添加为请求标头的方法。
I am looking for a way to get the original URL during RewriteRule and append it to the query string as an additional parameter or add it as a header to the request.
我该怎么做?
推荐答案
将内容添加到查询字符串很简单(只需在问号后写一些内容,并且不要忘记使用QSA标志来附加原始查询字符串);而且,您可以捕获整个URI并附加以下内容:
Appending stuff to the query string is straightforward (just write stuff after a question mark, and don't forget to use the QSA flag to append the original query string); and, well, you can just capture the whole URI and append that:
RewriteRule (.*) test.php?uri=$1 [QSA]
或者,您可以尝试以下几种服务器变量提供有关请求的信息:
Alternatively, you may try one of the several server variables providing info about the request:
RewriteRule .* test.php?uri=%{REQUEST_URI} [QSA]
请注意,服务器变量的内容在系统之间可能千差万别。
Note that the content of server variables may vary wildly between systems.
您也可以修改标头,但这并不是那么简单。查看此问题以了解解决方法。
You can also modifiy headers, but it's not as straightforward. Check out this question for a way to do it.
这篇关于在RewriteRule期间将原始url添加为标头或查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!