Solved

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

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

Don't Miss ATEN at InfoComm 2017!

Visit booth #2167 to see the  new ATEN VM3200 32 x 32 Modular Matrix Switch. Other highlights include the VE8950 4K HDMI Over IP Extender, VS1912 12-Port DP Video Wall Media Player  and VK2100 ATEN Control System. Register now with Free Pass Code ATEN288!

Question has a verified solution.

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

Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
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…

705 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