防止直接访问子文件夹,改为重定向

时间:2022-09-23 11:03:01

The structure looks like this:

结构是这样的:

html
->index.html
->subfolder
--->1.html
--->2.html

I want to prevent direct access when someone visits mysite.com/subfolder. The user should instead be directly redirected to the index.html on the parent folder.

我想防止有人访问mysite.com/子文件夹时直接访问。用户应该直接重定向到索引。在父文件夹上的html。

How is this possible with .htaccess?

如何使用.htaccess?

2 个解决方案

#1


1  

Create an htaccess file in the subfolder and add the following :

在子文件夹中创建一个htaccess文件,并添加以下内容:

RewriteEngine on

RewriteRule ^$ /index.html [L,R]

Remove the R flag if want to internally redirect (without changing the url) /subfolder to /index.html .

如果希望在内部重定向(不更改url) /子文件夹到/index,则删除R标志。html。

#2


0  

Is this working out for you?

这对你合适吗?

RewriteRule ^/subfolder/?$ http://yourdomain.com/index.html [R=301,L]

#1


1  

Create an htaccess file in the subfolder and add the following :

在子文件夹中创建一个htaccess文件,并添加以下内容:

RewriteEngine on

RewriteRule ^$ /index.html [L,R]

Remove the R flag if want to internally redirect (without changing the url) /subfolder to /index.html .

如果希望在内部重定向(不更改url) /子文件夹到/index,则删除R标志。html。

#2


0  

Is this working out for you?

这对你合适吗?

RewriteRule ^/subfolder/?$ http://yourdomain.com/index.html [R=301,L]