我运行XAMPP,并试图学习.htaccess如何工作。 我有一个像这样的文件结构:
/parent /foo /bar .htaccess
我只是想改变所有的foo
请求,并在它们之后附加一个GET参数。 例如:
foo/ foo/hello.php
变成:
bar/?test=yes bar/hello.php?test=yes
当我尝试把我的.htaccess文件中的<Directory>
指令:
<Directory "/foo"> Options +Indexes </Directory>
我得到以下错误日志:
[tue Sep 19 17:23:58.356362 2017] [core:alert] [pid 6336:tid 1900] [client :: 1:60018] C:/xampp/htdocs/parent/.htaccess:<目录不允许在这里
我检查了我的httpd.conf文件,一切正常。 我确定,因为如果我将.htaccess文件的内容改为:
Options -Indexes
它正确显示一个403错误。 如果我用+
replace-
它显示目录列表。
<Directory>
指令在.htaccess中是不允许的,为了满足你的需求,你甚至不需要在.htaccess中使用。
您可以在站点根(父) .htaccess
使用此规则:
RewriteEngine On RewriteCond %{QUERY_STRING} !(?:^|&)test=yes(?:&|$) [NC] RewriteRule ^foo/(.*)$ bar/$1?test=yes [NC,QSA,L]
根据手册, <Directory..
在.htaccess
是不允许的 。 您只能在服务器配置和虚拟主机中使用它。 你应该使用mod_rewrite
来代替。