我正在与我的班级一起处理一个似乎不起作用的 htaccess 文件的项目。我有这个:
SetEnvIf Request_URI ^ root=/myroot/
RewriteRule ^(assets|inc) - [L]
RewriteRule ^section[/]?$ %{ENV:root}section/index
RewriteRule ^section/function/(.*)$ %{ENV:root}index.php?type=section&action=function [L]
RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^section/(.*)$ %{ENV:root}index.php?type=section&action=view [L]
RewriteRule ^index\.php$ - [L]
其实我不明白的地方有三点:
如果我将 url 查询为/section/function/
,我应该得到 /myroot/index.php?type=section&action=function 但我进入localhost/section/function
浏览器,导致错误。url 是否双向翻译:myroot/index.php?type=section&action=function 在浏览器中显示为/section/function/
. 如果我删除最后一行,我会得到空白错误页面,为什么会这样?
编辑 :
如此符合 Olaf Dietsche 所说的,我将规则更改为
SetEnvIf Request_URI ^ root=/myroot/
RewriteRule ^(assets|inc) - [L]
RewriteRule ^section[/]?$ %{ENV:root}section/index
RewriteRule ^section/function/(.*)$ %{ENV:root}?type=section&action=function [L]
RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^section/(.*)$ %{ENV:root}?type=section&action=view [L]
RewriteRule ^index\.php$ - [L]
但是当我单击时<a href="section/somefunction"></a>
,我会看到一个页面localhost/section/some function
。我真的不知道怎么回事......