htaccess to multiple folders

I have written a rule that if a file doesn’t exist, then look for it in “sub1” folder, for example:

when someone goes to www.example.com/file15 it will rewrite to -> www.example.com/sub1/file15, and it works

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ sub1/$1 [QSA]

But there are more folders than sub1, so if a “file15” doesn’t exist in sub1, then look for it in folder sub2, and if it’s not in sub2, then rewrite to sub3.

I tried this but doesn’t work:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ sub1/$1 [QSA]

RewriteCond sub1/%{REQUEST_FILENAME} !-f
RewriteCond sub1/%{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ sub2/$1 [QSA]

Based on OP’s crosspost, he wants a shorter URL. OP was advised to look into MVC and writing a router to map URL’s to filenames.

Sponsor our Newsletter | Privacy Policy | Terms of Service