Solved

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

Posted on 2014-09-26
6
359 Views
Last Modified: 2014-09-29
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!
0
Comment
Question by:bbdesign
  • 2
  • 2
6 Comments
 
LVL 35

Expert Comment

by:Terry Woods
ID: 40347451
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
 

Author Comment

by:bbdesign
ID: 40347509
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
 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 40347709
Put the rule detecting 'root' before the general rule:
RewriteRule ^/?$ /default.htm [NC,L]
RewriteRule ^/?([^\.]+)$ /$1.htm [NC,L]

Open in new window

0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 40349488
Let us know how you go... more solutions might be suggested if Steve's doesn't work for you.
0
 

Author Comment

by:bbdesign
ID: 40350901
That seems to have fixed it, thanks!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Running classic asp applications under Windows Server 2008 R2 (x64) and IIS 7 is not as easy as one may think. It took me a while to figure it out while getting error 8002801d a few times. After you install the OS you will need to install the fol…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

746 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

9 Experts available now in Live!

Get 1:1 Help Now