Solved

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

Posted on 2014-09-26
6
373 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
A phishing scam that claims a recipient’s credit card details have been “suspended” is the latest trend in spoof emails.
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…

776 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