Apache Mod_Rewrite folder if index file does not exist

Is there a way to use Mod_Rewrite to redirect if the requested page is a folder and an index page does not exist in that folder?

For example:

Someone types "http://some.site.com/folder/"

If a file that is not considered an index is not located in this folder, then redirect to whatever page. It would likely need to check for any of the following: index.htm, index.html, index.asp, index.php, as well as maybe things like default.html or home.html.

Alternately, can Mod_Rewrite actually check to see that the default pages on the server are and then check for the existence of pages in that list?
LVL 18
Hube02Asked:
Who is Participating?
 
caterham_wwwCommented:
> can Mod_Rewrite actually check to see that the default pages on the server are

No, you can't read directives provided by different modules with mod_rewrite. You'll use a condition per file you'd like to check like:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}index.htm !-f
RewriteCond %{REQUEST_FILENAME}index.html !-f
RewriteCond %{REQUEST_FILENAME}index.asp !-f
RewriteCond %{REQUEST_FILENAME}index.php !-f
# regEx requires apache 2+
RewriteRule ^.++(?<=/)$ /whatever.html [L,NS]

Open in new window

0
 
Hube02Author Commented:
Sorry I didn't close this earlier, forgot it was here. Thanks for the help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.