Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Apache Mod_Rewrite folder if index file does not exist

Posted on 2009-04-24
2
Medium Priority
?
1,463 Views
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 "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?
0
Comment
Question by:Hube02
2 Comments
 
LVL 27

Accepted Solution

by:
caterham_www earned 2000 total points
ID: 24224154
> 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
 
LVL 18

Author Closing Comment

by:Hube02
ID: 31576904
Sorry I didn't close this earlier, forgot it was here. Thanks for the help.
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses
Course of the Month13 days, 9 hours left to enroll

581 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