Apache .htaccess<目录在这里不允许 [英] Apache .htaccess <Directory not allowed here

查看:80
本文介绍了Apache .htaccess<目录在这里不允许的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行XAMPP,试图了解.htaccess的工作方式.我有一个看起来像这样的文件结构:

I run XAMPP and I'm trying to learn how .htaccess works. I have a file structure that looks something like this:

/parent
    /foo
    /bar
    .htaccess

我只是想将所有foo请求更改为bar,并在其后附加GET参数.例如:

I simply want to change all foo requests to bar with a GET parameter appended after them. For example:

foo/
foo/hello.php

变成:

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

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

When I try to put the <Directory> directive in my .htaccess file:

<Directory "/foo">
    Options +Indexes
</Directory>

我收到以下错误日志:

[2017年9月19日星期二17:23:58.356362] [core:alert] [pid 6336:tid 1900] [client :: 1:60018] C:/xampp/htdocs/parent/.htaccess:<目录未允许在这里

[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文件的内容更改为:

I checked my httpd.conf file and everything is alright. I'm sure because if I change the contents of the .htaccess file to simply:

Options -Indexes

它正确显示403错误.如果将-替换为+,它将显示目录列表.

It correctly displays a 403 error. If I replace the - with +, it shows the directory listing.

推荐答案

<Directory>指令,而为了满足您的要求,甚至在.htaccess中也不需要此指令.

<Directory> directive is not allowed in .htaccess and for meeting your requirements you don't even need this in .htaccess.

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

You can use this rule in site root (parent) .htaccess:

RewriteEngine On

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

这篇关于Apache .htaccess&lt;目录在这里不允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆