清理 IIS 5.1 和 PHP 5 上的 PathInfo URL 和查询字符串
我正在尝试使用 FastCGI 在 PHP 5.3 和 IIS 5.1 上使用查询字符串参数来获取“干净”的 PathInfo 样式 URL。我发现我可以使用:
(1) http://www.example.com/index.php?/path/to/foo/
但不能:
(2) http://www.example.com/index.php/path/to/foo/
(注意缺少的?)
这不是一个大问题,直到我想将 URL 与查询字符串混合,例如:
(3) http://www.example.com/index.php?/path/to /foo/?color=blue&size=small
这使得我的 $_GET 看起来像:
Array
(
[/myapp/foo/bar?colour] => blue
[size] => small
)
有没有办法让像下面 (4) 这样的 URL 方案正常工作,并且 $_GET 在 IIS 5.1 上正确填充?
(4) http://www.example.com/index.php/path/to/foo/?color=blue&size=small
PS - 我记得是以前可以做到这一点,但我怀疑我当时使用的是 Apache 而不是 IIS。无法为此使用 Apache。然而,生产服务器有 IIS7(我的机器上只有 IIS 5.1)。
I'm trying to get 'clean' PathInfo style URLs with query string parameters working on PHP 5.3 and IIS 5.1 using FastCGI. I've found that I can use:
(1) http://www.example.com/index.php?/path/to/foo/
but not:
(2) http://www.example.com/index.php/path/to/foo/
(Note the missing ?)
Which isn't a big issue until I want to mix URLs with a query string like:
(3) http://www.example.com/index.php?/path/to/foo/?color=blue&size=small
That makes my $_GET look like:
Array
(
[/myapp/foo/bar?colour] => blue
[size] => small
)
Is there way to get a URL scheme like (4) below to work, and with $_GET being populated correctly on IIS 5.1?
(4) http://www.example.com/index.php/path/to/foo/?color=blue&size=small
P.S. - I remember being able to do this before, but I suspect I was using Apache at the time and not IIS. Unable to use Apache for this. However the production server has IIS7 (I only have IIS 5.1 on my machine).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 (3),您只需将查询字符串视为单个文本即可。您不应该使用
$_GET
- 您应该直接使用QUERY_STRING
环境变量。您应该得到/path/to/foo/?color=blue&size=small
。对于 (4),您应该连接
PATH_INFO
和QUERY_STRING
环境变量,并使用?
连接,并使用该值。同样,您应该得到/path/to/foo/?color=blue&size=small
。这是因为PATH_INFO
具有/path/to/foo
且QUERY_STRING
具有color=blue&size=small
。For (3), you simply need to treat the query-string as a single piece of text. You should not be using
$_GET
- you should be using theQUERY_STRING
environment variable directly, instead. You should get/path/to/foo/?color=blue&size=small
.For (4), you should concatenate the
PATH_INFO
andQUERY_STRING
environment variables, joined with a?
, and use that value. Again, you should get/path/to/foo/?color=blue&size=small
. This is becausePATH_INFO
has/path/to/foo
andQUERY_STRING
hascolor=blue&size=small
.