Apache Mod_Rewrite folder if index file does not exist

Posted on 2009-04-24
Last Modified: 2012-06-21
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 ""

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?
Question by:Hube02
    LVL 27

    Accepted Solution

    > 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

    LVL 18

    Author Closing Comment

    Sorry I didn't close this earlier, forgot it was here. Thanks for the help.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Apache 2.4 configurations 4 16
    php and mysqli 15 28
    XAMPP 3 37
    Change local server setting in php 6 31
    If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
    It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now