如何将没有索引文件的子目录重定向到404页

问题描述 投票:2回答:3

我有一个网站,example.com

我也有以下子目录:

example.com/dir1/
example.com/dir2/
example.com/dir3/

现在,如果他们尝试访问,我希望将访问者重定向到404:

example.com/dir1 /

但以防万一,当他们尝试访问时:

example.com/dir1/example.php

下面是我的.htaccess:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ / [L,R=301]

Options -Indexes

在htaccess之上,当我尝试按以下方式访问任何子目录时,出现默认错误:

Access forbidden!

    You don't have permission to access the requested directory. There is either no index document or the directory is read-protected.

    If you think this is a server error, please contact the webmaster.

    Error 403

    localhost
    Apache/2.4.16 (Win32) OpenSSL/1.0.1p PHP/5.6.12
php apache .htaccess redirect
3个回答
1
投票

尝试在您的.htaccess文件中使用它!


ErrorDocument 404 /filenotfound.html

IndexIgnore *

0
投票

尝试:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L,R=404]

0
投票

我进行了一些研究,发现了这一点:

Options -Indexes

来自here

它将抛出403-禁止访问,这比使用列出的文件自动索引更好。

© www.soinside.com 2019 - 2024. All rights reserved.