如何将 / 的索引重定向到网站?

How to redirect the Index of / to a website?

我创建了一个 VirtualHost 来访问 php 文件,我想允许访问此页面和 folder1 中的文件。 这是我的文件夹:

root
|mywebsite.php
|.htaccess
|otherfiles
|
|--images
|  |image.jgp
|
|--style
|  |style.css
|
|--folder1
|  |a_lot_of_folders

我可以拒绝访问根目录中的其他文件。如果 URL 是:www.ipaddress/www.ipaddress/otherfiles 它将重定向到 www.ipaddress/mywebsite.php。 但我想要的是只允许访问 php 文件和 folder1 中的文件。但是如果 URL 看起来像这样:www.ipaddress/folder1 或这样:www.ipaddress/style 它会打开 Index of /folder 而我不想要这个。

这是我的 .htaccess 文件:

RewriteEngine on

RewriteRule ^$ mywebsite.php
RewriteRule ^otherfiles$ mywebsite.php # This is for each files in the root folder except the php one
RewriteRule ^/folder1? mywebsite.php # This doesn't work

我试图重写 URL,但它有 /folder1 但它什么也没做

试试这个作为你的最后规则:

RewriteRule ^folder1/?$ mywebsite.php [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^folder1/ mywebsite.php [L,NC]