Dreni Dreni - 1 month ago 9
Apache Configuration Question

Prevent direct access to subfolder, redirect instead

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.

How is this possible with .htaccess?

Answer

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

RewriteEngine on

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

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