【发布时间】:2021-06-30 08:07:27
【问题描述】:
我创建了一个 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 时,我尝试重写它,但它什么也没做
【问题讨论】:
标签: .htaccess redirect url-rewriting