如何重定向所有尝试访问文件夹但索引到服务器的尝试?

时间:2019-03-24 21:54:12

标签: php html5 apache .htaccess

我正在创建一个新的网站。

该网站的结构为:

root
├─ .htaccess
├─ Index.php
└─ Data
   └─Logo.png

我的索引页面包含:

<html>
    <head>
        <meta charset="UTF-8">
    </head>
    <body>
        <img src="Data/Logo.png" alt="logo" height="42" width="42"> 
    </body>
</html>

和我的.htaccess:

ErrorDocument 404 https://www.example.com/

RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

Options +SymLinksIfOwnerMatch 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

RewriteEngine On 
RedirectMatch 404 ^/Data/.*$ 

我的问题:

如果在.htaccess文件中我设置了RedirectMatch 404 ^/Data/.*$,则没有访问者可以访问example.com/Data/Logo.png,但是index.php无法显示图像。

如果在.htaccess文件中我设置了RedirectMatch 404 ^/Data/?$,则Index.php可以显示图像,但是任何访问者都可以访问example.com/Data/Logo.png

我希望/Data存储图像,php函数,样式和其他所有类。

我的问题:

我该如何配置htaccess文件以拒绝所有访问者的访问,但允许Index.php(以及网站上的任何其他页面)访问该文件夹?

0 个答案:

没有答案