mike
mike

Reputation: 11

Redirect to subfolder but allow the access to other subfolders if requested with .htaccess

I want to redirect the requests from the root of my site (or non existing requests) to a subfolder my/subfolder/index.php but allow the access to other subfolders that exists.

I have searched and tried many questions but no one fit my scenario!

Upvotes: 1

Views: 269

Answers (1)

matthew
matthew

Reputation: 2932

One pretty standard option might be:

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ my/subfolder/index.php [NC,L]

The first three lines check if the resource exists at the current location and if so the fourth line returns that resource. The fifth line rewrites everything else to your specified index.php

Another option is:

FallbackResource my/subfolder/index.php

Which does pretty much the same thing without all the complicated rewrite rules.

Upvotes: 2

Related Questions