URL rewrite using regular expressions to create default document for htaccess and IIRF

I'm using Ionic Isapi Rewrite Filter to do URL rewriting for IIS 6.0. It uses syntax that should be nearly identical to htaccess. I have these two rules in place:

RewriteRule ^([^\.]+)$ $1.htm [NC,L]
RewriteRule ^([^\.]+)$ $1.asp [NC,L]

The take whatever the string after the domain is (i.e., http://www.mydomain.com/testurl) and convert it to a document, in this case http://www.mydomain.com/testurl.htm

However, these rules don't work for http://www.mydomain.com or http://www.mydomain.com/

In those cases, I need it to go to default.htm.

In htaccess, I use this:
DirectoryIndex default.htm

...however, DirectoryIndex doesn't seem to be valid in IIRF syntax. This is what I've come up with so far:

RewriteRule ^?$ /default.htm

However, that doesn't work. This is difficult to debug, there is an error log but its hard to see what is going on "under the hood." Would appreciate any advice.

Thanks!
Brad BansnerWeb DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Terry WoodsIT GuruCommented:
I'd suggest trying this:

RewriteRule ^/?$ /default.htm

Open in new window


I'm no apache/iis/rewriting guru, but I do know lots about regex's. Hopefully that will do the trick.

The ? character in a regular expression means to match zero or one of the previous character or group. In your attempt, there isn't a previous character or group (there's just the start-of-line placeholder), which may be illegal, or just fail to work. I've changed the pattern to match zero or one / characters only.
0
Brad BansnerWeb DeveloperAuthor Commented:
Thanks for that. I think I am getting closer. I figured out how to enable more detailed logging to see what is going on. I am seeing this:

DoRewrites: Rewrite Url to: '/.htm'

Open in new window


So perhaps my initial rule is actually causing the problem:

RewriteRule ^([^\.]+)$ $1.htm [NC,L]

Can that be re-written to ignore cases where I want default.htm to load? If I put in http://www.mydomain.com it is rewriting to ".htm" for some reason. I think the parser is not getting to the new rule you suggested at all, because the first one is picking it up. Does this make sense?
0
Steve BinkCommented:
Put the rule detecting 'root' before the general rule:
RewriteRule ^/?$ /default.htm [NC,L]
RewriteRule ^/?([^\.]+)$ /$1.htm [NC,L]

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Terry WoodsIT GuruCommented:
Let us know how you go... more solutions might be suggested if Steve's doesn't work for you.
0
Brad BansnerWeb DeveloperAuthor Commented:
That seems to have fixed it, thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.

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.