Reputation: 79
I want to redirect to the main domain if a directory(any) exists but does not have an index file(index.php/index.html), How to do that? I tried the below code but does not work.
Options +FollowSymlinks -Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ %1 [R=301,L]
Upvotes: 1
Views: 45
Reputation: 41219
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{DOCUMENT_ROOT}/$1/index.php !-f [OR]
RewriteCond %{DOCUMENT_ROOT}/$1/index.html !-f
RewriteRule ^(.+)/$ / [L,R]
This will redirect a directory request to /
if the /index
file doesn't exist in that folder.
Upvotes: 1