?
Solved

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

Posted on 2014-09-26
6
Medium Priority
?
408 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 51

Accepted Solution

by:
Steve Bink earned 2000 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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

Debug Tools to analyse IIS process: This article focus on taking memory dumps from IIS to determine which code is taking more time and to analyse which calls hangs/causes more CPU usage. To take dumps,download the following. Install1: To st…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
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…
Suggested Courses

770 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