在Apache2中将目录索引设置为.html文件

时间:2021-09-14 11:11:19

I have a Debian web-server with Apache2 installed and need to set in one directory DirectoryIndex to .html file (exactly this name - .html). But when I try to open page from browser it send 403 error. I've changed apache2.conf (set to allow .ht files), I placed .htacess file in directory and set in it:

我有一个安装了Apache2的Debian Web服务器,需要在一个目录中设置DirectoryIndex到.html文件(正是这个名字 - .html)。但是当我尝试从浏览器打开页面时,它会发送403错误。我已经更改了apache2.conf(设置为允许.ht文件),我将.htacess文件放在目录中并设置在其中:

DirectoryIndex .html index.php index.html
AllowOverride All
Order Deny,Allow
Allow from all

But it still not work and displays 403 error. What i doing wrong and what i forget to do?

但它仍然无法正常显示403错误。我做错了什么,忘了做什么?

2 个解决方案

#1


5  

The correct answer is:

正确答案是:

<FilesMatch "^\.html">
        Order deny,allow
</FilesMatch>

DirectoryIndex .html

#2


1  

Sounds like you have a rule somewhere in your apache file that denys access to files starting with a .. This is generally a Good Thing, as a lot of sensitive files start with dots (ie: .htaccess, .svn, .git, .htpasswd, etc etc).

听起来你的apache文件中有一条规则拒绝访问以...开头的文件。这通常是一件好事,因为许多敏感文件以点开头(即:.htaccess,.svn,.git ,. htpasswd等等)。

You might be able to get around the issue with something like this:

您可以通过以下方式解决问题:

<FilesMatch "^\.html">
 Order allow,deny
 Allow from all
</Files>

Disclaimer: This seems like a hack. I don't know what you're trying to do, but there's probably a cleaner, less error prone way to do it.

免责声明:这似乎是一个黑客。我不知道你要做什么,但可能有一个更清洁,更不容易出错的方法。

#1


5  

The correct answer is:

正确答案是:

<FilesMatch "^\.html">
        Order deny,allow
</FilesMatch>

DirectoryIndex .html

#2


1  

Sounds like you have a rule somewhere in your apache file that denys access to files starting with a .. This is generally a Good Thing, as a lot of sensitive files start with dots (ie: .htaccess, .svn, .git, .htpasswd, etc etc).

听起来你的apache文件中有一条规则拒绝访问以...开头的文件。这通常是一件好事,因为许多敏感文件以点开头(即:.htaccess,.svn,.git ,. htpasswd等等)。

You might be able to get around the issue with something like this:

您可以通过以下方式解决问题:

<FilesMatch "^\.html">
 Order allow,deny
 Allow from all
</Files>

Disclaimer: This seems like a hack. I don't know what you're trying to do, but there's probably a cleaner, less error prone way to do it.

免责声明:这似乎是一个黑客。我不知道你要做什么,但可能有一个更清洁,更不容易出错的方法。