漂亮的 URL 有时会用“?”重写。有时没有
我希望有人能回答“为什么”是这样的:
有时我可以使用:
...
RewriteRule ^(.*)$ index.php/$1 [L]
,有时上面的方法不起作用,我必须使用:
...
RewriteRule ^(.*)$ index.php?/$1 [L]
主要区别是添加了 ? ...我通常会在不同的系统设置(fastcgi vs module vs cgi)上看到这种情况,但还没有进行足够的设置来查看该模式。
我猜测这与 apache/setup 如何解析 path/path_info 数据有关。欢迎任何想法,理想情况下我想对为什么会出现这种情况以及何时发生有一个可靠的解释。
在同一个线程上...有时 Apache 不会输出 PATH_INFO 环境变量,这可能是造成这种情况的根本原因,但我想知道这是为什么。
I hope someone can answer "why" this is the case:
There are times I can use:
...
RewriteRule ^(.*)$ index.php/$1 [L]
and then there are times where the above doesn't work and I must use:
...
RewriteRule ^(.*)$ index.php?/$1 [L]
the main difference being the addition of ?
... I typically see this happen on different system setups, fastcgi vs module vs cgi, but haven't done enough setups to see the pattern.
I am guessing that it is related to how the apache/setup parses path/path_info data. Any thoughts are welcomed, ideally I'd like to have a solid explanation of why this is and when it occurs.
On the same thread ... Sometimes Apache does not output PATH_INFO
environment var which might be the root cause of this, but I wonder why that is.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这 ?是查询字符串开头的标记。
因此,基本上,您的第一条规则将 URL
"x"
重写为目录index.php
中的文件"x"
,第二条规则重写 URL"x"
到带有参数"x"
的index.php
文件。 [(顺便说一句,我不知道如何检索文件中没有名称的变量,通常您使用?var=value&var2=value2
等...)The ? is the marker of the beginning of the query string.
So basically your first rule rewrite a URL
"x"
to a file"x"
in the directoryindex.php
, the second rewrite a URL"x"
to theindex.php
file with parameter"x"
. [(BTW I don't know how to retrieve a variable with no name in the file, usually you use?var=value&var2=value2
etc...)