Rewrite w/alternative response

My problem is actually for IIS7 Rewrite but I figure if there is a mod-rewrite solution for apache, then I can learn to adapt it myself.

So - I will ask if this is possible in Apache using a htaccess file :slight_smile:

RewriteEngine on
RewriteRule ^(.*)$ $1.php

Quite simply, this should allow you to hide the PHP extension in the filename.
(ie: www.domain.com/myfile will actually load www.domain.com/myfile.php)

But I need something a little different. Is there any way to have it search for multiple extensions (in a given list) and return the first one found? (.htm, .html, .php)

Eg: Look for “myfile.htm”, if that doesn’t exist check for “myfile.html” if that doesn’t exist check for “myfile.php”, and if none of those exist it would simply return a 404.

I KNOW - Apache has “MultiViews” for this. But like I said at the beginning of the post, I am actually fishing for a solution I can adapt to the IIS7 Rewrite module. IIS does not have MultiViews.

Does IIS know RewriteCond with -f ?


RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI}.php -f
RewriteRule .? index.php [L]

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI}.html -f
RewriteRule .? index.html [L]

Something like that
(untested)

SOLVED!

I figured this out with Conditions.

1: Check to see if the File exists with the extension added.
2: If it exists, rewrite.

It it doesn’t find the file, it will go to the next condition and check again, etc… etc…

No need to post the full results here, as Apache has MultiViews which is much easier :slight_smile:

ScallioXTX: Exactly. Your post must have come in while I was writing my “solved” answer. Appreciate the guidance!

Yes, seems I posted just 1 minute before you did.
And you’re welcome :slight_smile: