mod_rewrite的帮助来传递查询字符串完整路径 [英] mod_rewrite help to pass full path with query string
问题描述
我在做基于整个URL一些缓存,包括查询字符串,并且需要Apache来识别文件并使用它。这似乎找到了比赛,但随后呈现的文件之前剥离查询字符串了。
网址:www.somesite.com/default.asp?foo=bar
在缓存文件夹文件系统缓存的网页文件名:Default.asp的富=栏
我在改写当前的尝试:
的RewriteCond / site_root /缓存/%{} REQUEST_FILENAME?%{} QUERY_STRING -f
重写规则^ * $ / site_root /缓存/%{} REQUEST_FILENAME?%{} QUERY_STRING [L,QSA]
我发现我需要的解决方案。
看来,阿帕奇真的想查询字符串拉出成一组则params的,这是正常的。
为了拉一个比在Apache我刚刚更换了?在同一个字符串|。一旦我做了,它没有看到字符串作为查询字符串了。由于PARAMS在我的情况是不相关的,它工作正常。我所要做的就是确保我写出来的文件名与管道,而不是一个问号。很容易的。
欢迎,如果你有一个更好的解决方案进行评论。
下面是在做它为我的规则。因为Apache不能识别结果作为它知道一个MIME,我强迫它为text / html。
的RewriteRule ^(。+)$ / site_root /缓存/%{HTTP_HOST} $ 1 |%{} QUERY_STRING [L,T = text / html的]
I'm doing some caching based on the whole url, including query string, and need Apache to recognize the file and use it. It seems to find a match but then strips the query string off before rendering the file.
url: www.somesite.com/default.asp?foo=bar
Cached page filename on the filesystem in the cache folder: default.asp?foo=bar
My current attempt at rewrite:
RewriteCond /site_root/cache/%{REQUEST_FILENAME}?%{QUERY_STRING} -f
RewriteRule ^.*$ /site_root/cache/%{REQUEST_FILENAME}?%{QUERY_STRING} [L,QSA]
I found a solution that works for my need.
It seems that Apache really wants to pull out the query string into a set of params, which is normal.
In order to pull one over on Apache I just replaced the ? in the string with a |. Once I did that it didn't see the string as a query string anymore. Since the params are irrelevant in my case it works fine. All I have to do is make sure I write out the filename with a pipe instead of a question mark. Easy enough.
Feel free to comment if you have a better solution.
Here's the rule that's doing it for me. Since Apache doesn't recognize the result as a MIME it knows, I force it to text/html.
RewriteRule ^(.+)$ /site_root/cache/%{HTTP_HOST}$1|%{QUERY_STRING} [L,T=text/html]
这篇关于mod_rewrite的帮助来传递查询字符串完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!