Help! Can't get my rules right

Topics: User Forum
Nov 29, 2006 at 9:01 PM
Hi, I'd really appreciate some help with my rules! On the face of it, I think it should be quite simple but I can't seem to get everything working. I need to map all URLs to a single page whilst retaining any querstring if there is one.

So:
/sub --> default.asp
/sub/ --> default.asp
/sub/dir --> default.asp
/sub/dir/ --> default.asp
/sub?id=20 --> default.asp?id=20
/sub/?id=20 --> default.asp?id=20
/sub/dir?id=20 --> default.asp?id=20
/sub/dir/?id=20 --> default.asp?id=20
etc. etc.

I'll then use HTTPXREWRITE_URL to work out which page was actually requested.

Can someone help me write a rule to do this? I'd really appreciate it!

I should also say that I'm using a rewritecond to exclude certain directories and extensions - I'm using this:
(I've written "asterisk" instead of the symbol as I know this forum gets confused)

RewriteCond %{HTTP_URL} ^(?!/images/|/stylesheets/|/graphics/|/admin/).asterisk I
RewriteCond %{HTTP_URL} ^(\.gif\.jpg\.jpeg\.css\.js$ I

Many thanks,

Ant.
Nov 29, 2006 at 9:03 PM
Looks like the forum has mangled my rewrite rules. There should be a bar between each extension.
Dec 5, 2006 at 2:18 PM
I think I've finally got it working. Rather than use a Rewritecond to ignore .jpg, .gif, /images/ etc., I've built it into the rewrite rule itself. I've had to use 2 in order to cover everything. No doubt there's a more efficient way of writing these but at least it works. Here are my rules, no doubt the forum software will mangle them. I've used the word "asterisk" instead of the symbol.

ReWriteRule ^(?!.asterisk\.gif$)(?!.asterisk\.jpg$)(?!.asterisk\.jpeg$)(?!.asterisk\.css$)(?!.asterisk\.ico$)(?!.asterisk\.js)(?!/stylesheets/.asterisk)(?!/admin/.asterisk)(?!/graphics/.asterisk)(?!/images/.asterisk)/(.asterisk)(/?\?)(.asterisk)$ /menu.asp?$3 L,I,U

ReWriteRule ^(?!.asterisk\.gif$)(?!.asterisk\.jpg$)(?!.asterisk\.jpeg$)(?!.asterisk\.css$)(?!.asterisk\.ico$)(?!.asterisk\.js)(?!/stylesheets/.asterisk)(?!/admin/.asterisk)(?!/graphics/.asterisk)(?!/images/.asterisk)/(.asterisk) /menu.asp L,I,U

I have a suggestion which I don't think has been implemented. When using IIS Rewrite (a different product which I can't get to work properly on Win2k3 server), you could have a non-rewriting rule. For instance, if I didn't want a URL with /images/ rewritten, I'd use:
RewriteRule ^/images/.asterisk - L
Using the L would mean no other rules would be run after that one. So I had a whole list of different exclusions with my actual rewrite rules at the end. It meant it was very easy to implement and it would be great if this was implemented in ISAPI Rewrite.

Thanks!