gpt4 book ai didi

regex - Apache .htaccess <此处不允许使用目录

转载 作者:行者123 更新时间:2023-12-02 00:54:59 25 4
gpt4 key购买 nike

我运行 XAMPP,并且正在尝试了解 .htaccess 的工作原理。我的文件结构如下所示:

/parent
/foo
/bar
.htaccess

我只是想更改所有foo请求 bar在它们后面附加一个 GET 参数。例如:

foo/
foo/hello.php

变成:

bar/?test=yes
bar/hello.php?test=yes

当我尝试输入 <Directory> 时我的 .htaccess 文件中的指令:

<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: <Directory not allowed here

我检查了我的 httpd.conf 文件,一切正常。我确定,因为如果我将 .htaccess 文件的内容更改为简单:

Options -Indexes

它正确显示 403 错误。如果我替换 -+ ,它显示目录列表。

我做错了什么?

最佳答案

<Directory> .htaccess 中不允许使用指令,为了满足您的要求,您甚至不需要在 .htaccess 中使用该指令。

您可以在站点根目录(父级).htaccess中使用此规则:

RewriteEngine On

RewriteCond %{QUERY_STRING} !(?:^|&)test=yes(?:&|$) [NC]
RewriteRule ^foo/(.*)$ bar/$1?test=yes [NC,QSA,L]

关于regex - Apache .htaccess <此处不允许使用目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46303236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com