MOD-改写THE_REQUEST和(或REQUEST_URI REQUEST_FILE)给出了不同的文件名 - 为什么? [英] mod-rewrite THE_REQUEST and (REQUEST_URI or REQUEST_FILE) give different filenames - why?
问题描述
我与mod-rewrite实验。我以为我想要的东西很简单,但我不通过REQUEST_URI获得所要求的文件的URI。相反的内交名字被传递。
I was experimenting with mod-rewrite. I thought what I wanted was simple but I don't get the requested file's URI via REQUEST_URI. Rather the delived name is passed on.
借助手动说:
THE_REQUEST
THE_REQUEST
完整的HTTP请求
通过浏览器向服务器发送行
(例如,GET /index.html HTTP / 1.1)。
这不包括任何附加的
浏览器发送头。这个
值尚未转义
(德codeD),与大多数其他变量
下文。
The full HTTP request line sent by the browser to the server (e.g., "GET /index.html HTTP/1.1"). This does not include any additional headers sent by the browser. This value has not been unescaped (decoded), unlike most other variables below.
REQUEST_URI
REQUEST_URI
请求的资源
在HTTP请求行。 (在里面
上面的例子,这将是
/index.htm」明明)。
The resource requested in the HTTP request line. (In the example above, this would be "/index.html".)
不过两人在我的测试中给出不同的文件名。我有一个bootstrap.php中,通过它我想送所有请求。这是测试文件:
However the two give different file names in my tests. I have a bootstrap.php through which I wanted to send all requests. This is the test file:
<?php
echo $_GET['requestedURI'];
?>
在.htaccess文件我有:
on the .htaccess file I have:
### REWRITE RULES ###
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .+ bootstrap.php?requestedURI=%{REQUEST_URI} [L]
请求 HTTP://localhost/test.htm
推出 /bootstrap.php
如果我在.htaccess把THE_REQUEST代替REQUEST_URI我得到获取/test.htm HTTP / 1.1
if I put THE_REQUEST instead of REQUEST_URI in the .htaccess I get GET /test.htm HTTP/1.1
那么,为什么不满足于THE_REQUEST?好了,只要一个查询字符串存在的东西打破。如果我要求: HTTP://localhost/test.htm X = 1&安培; Y = 2
我收到获取/test.htm?x=1第一个符号打破的东西。我认为应该是可能的26%,以取代在查询字符串的所有&符号,以便它会工作,但我没到目前为止...
So why not settle for THE_REQUEST? Well, as soon as a query string exists things break. If I request: http://localhost/test.htm?x=1&y=2
I get GET /test.htm?x=1 the first ampersand breaks things. I think it should be possible to replace all ampersands in the querystring with %26 so that it would work but I did not manage so far...
因此,谁能知道为什么REQUEST_URI失败,如何解决它或如何改写与号至26%的查询字符串?
So can anyone tell why REQUEST_URI fails and how to fix it or how to rewrite the ampersands to %26 in the query string?
感谢。
编辑:上述报告适用于XAMPP 1.7.3在Win 7.我在其间尝试过生产Linux系统上有REQUEST_URI返回它应该
The above report applies to xampp 1.7.3 on Win 7. I tried it on a production Linux system in the meantime and there REQUEST_URI returns what it should.
推荐答案
您无需显式传递请求的URI路径和查询,你可以通过 $ _ SERVER在PHP访问['REQUEST_URI ']
。因此,这应该足够了:
You don’t need to explicitly pass the requested URI path and query as you can access it in PHP via $_SERVER['REQUEST_URI']
. Thus this should suffice:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .+ bootstrap.php
这篇关于MOD-改写THE_REQUEST和(或REQUEST_URI REQUEST_FILE)给出了不同的文件名 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!