Newbie need Guru/Expert for rules optimization

Topics: Developer Forum, Project Management Forum, User Forum
Nov 27, 2008 at 3:43 PM

Hi to all,
Shortly i have a complex website (Windows 2003 + IIS6 + SQL2005) with many sub-folders, 90% is ajax based and at the end i've decide to offer the chance for the users to have a personal URL as myspace like

I need help to OPTMIZE those rules below  because i think they are too much than i need (i think)

So all those rules are made only for offer this feature:

Imagine for example that an ajax request is made every 10 seconds and this request will be processed many times by IIRF

So i try to read all the IIRF documentation (i am not so expert with regular expression) but this is the best that i can do, maybe i am missing some RewriteCond, so please can someone give me a tip how to optmize the rules below ?

I will happy to hear your tips and tricks.

Really thanks in advance

p.s. the first 3 rows, i took it from an example, but i failed, because i want to offer the chance for a user to type:   (without WWW)


RewriteLogLevel 0
# 1 Redirect to the proper host if necessary
# 2 RewriteCond %{HTTP_HOST} ^(?!www\.mysite\.com)(.+)$ [I]
# 3 RewriteRule ^(.*)$$1     [R=301,L]

# rewrite default.asp when type only or javascript redirect
RewriteRule  ^/$  /default.asp  [I,L]

# rewrite when type only or javascript redirect
RewriteRule  ^/member/$  /member/default.asp  [I,L]

# rewrite when type only or javascript redirect
RewriteRule  ^/join/$  /join/default.asp  [I,L]

# don't rewrite any request that ends with one of these extensions.
RewriteRule /(.*\.)(php|asp|aspx|xml|js|swf|flv|ico|jpg|png|jpeg|gif|ttf|sql|txt|htm|zip|css)   -   [I,L]

# skip all sub folder
RewriteRule ^/(.*)/(.*)$   -   [I,L]

# redirect to profile
RewriteRule  ^/(.*)$  /profile/default.asp?URL=$1


Dec 1, 2008 at 12:28 AM
I don't know what you mean about the first three rows.  You want the user to be able to type, but I don't know what you expect to happen when the user types that in.  They can type it in, and ... THEN WHAT? 

On the rest of the rules, you have only 6 of them.  Three of them apply default.asp to the request. You do know about the default document for IIS?  You can set this in the IIS configuration, no need for an IIRF rule for any of these.

Ok, that leaves 3 rules remaining.   I don't see a ton of optimization possible in any of those rules.
I would suggest that for the rule to handle all the extensions (swf|flv|ico|jpg etc), you might want to append a $ to the end of the URL pattern.  The $ means "end of the string" in regular expression language, which means that the request truly ends with .jpg or whatever the extension is.  Without that $, the request could match .css or .jpg (etc) anywhere in the request, not just at the end.  Maybe not exactly what you want.

You might want to add in a [L] at the end of the final rule, as well.

otherwise it looks good.  
Dec 2, 2008 at 9:46 AM
Really thanks Cheeso for your answer, comments and tips!

(about the first 3 rows)
Yes, i want the user type the URL short for access to the profile like or just for access it

May be i can do this by setting the host header name in ISS with and without WWW?: -> IP -> IP

But my idea was the IIR rewrite the URL in case WWW is missing, so how i can do that ?

(about default.asp)
Yes i know about the default document and i use it often but i notice if i type   <- with slash at the end, the default.asp is not loaded and the IIR redirect to the profile page (last rule)

(about optimization)
I was worry that too much rules use CPU resource a lot and this can decrease the speed of the server response because they are apply every 10 seconds when is performed the ajax request in background.

Thanks again for your feedback.

Dec 3, 2008 at 5:38 AM
One request every 10 seconds is not so much.  Even if you have 3 or 4 rules, it will be quite fast.