a couple of questions and some help with optimizing

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 6
Joined: 26 Mar 2012, 07:09

a couple of questions and some help with optimizing

12 Apr 2012, 17:52

QUESTION #1
As far as I understand how ISAPI REWRITE works, the .htaccess file is considered for each request. So no matter if I call http://www.site.com/myrewrite or http://www.site.com/gfx/spacer.gif - the .htaccess file is parsed/considered - correct?

QUESTION #2
If that answer to question #1 is true, can I write a rule in the very top of my .htaccess file that automatically ignores images? Something like this:

Code: Select all
RewriteCond %{REQUEST_FILENAME} \.(gif|png|jpg)$ [NC]
RewriteRule .* - [L]

What I am trying to do is if the request has a filename that ends in .gif, .png or .jpg, "redirect" to the same URL - effectively doing a quick break-out of the .htaccess file.

HELP WITH OPTIMIZING
This happens quite often at the company I work for; A customer has 3 language-specific sites: http://www.site.dk, http://www.site.no, http://www.site.se (I work for a scandinavian company :D)
These 3 sites are 99,5% the same and where therefore run each site on the same code-files stored in a folder called /site
This of course means, that these 3 sites will share the same .htaccess file.

And here comes the issues I need help with...

ISSUE #1
Suppose the customer only wants to run URL rewriting for http://www.site.dk and http://www.site.no (and NOT for http://www.site.se)

Can I somehow create a rule in the shared .htaccess file so that any requests to http://www.site.se are "ignored" so to speak - or rather, that I break out of the .htaccess file as quickly as possible?

Something like this:
Code: Select all
RewriteCond %{HTTP_HOST} www.site.se
RewriteRule .* - [L]

ISSUE #2
Suppose our customers has snagged a really good domain name that he wants to redirect to one of his existing sites - say http://www.supercoolsite.dk should redirect to http://www.site.dk

Current we handle this issue like this by having each of his domain names in our HTTP_HOST conditions and then do the redirect after we passed through the .htaccess file. Like this:

Code: Select all
RewriteCond %{HTTP_HOST} (www.site.dk|www.supercoolsite.dk)
RewriteRule ^myrewrite$ /page1.cfm [L]

I have a theory however, that we should try to do this in the .htaccess file instead, since it would get us where we need to go faster (with less requests).

As far as I can work out, it should probably be something like:
Code: Select all
RewriteCond %{HTTP_HOST} (www.supercoolsite.dk) [NC]
RewriteRule ^(.*)$ http://www.site.dk/$1 [R=301,L]

Does that seem right?

I am looking forward to hearing from the experts - any help and/or comments will be greatly appreciated.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: a couple of questions and some help with optimizing

13 Apr 2012, 06:54

Question #1
Correct

Question #2
Yes, the rule is correct
Code: Select all
RewriteCond %{REQUEST_FILENAME} \.(?:gif|png|jpg)$ [NC]
RewriteRule .* - [NC,L]

Or it could be:
Code: Select all
# Ignore images, asp, css,etc
RewriteRule (.*\.(?:jpg|asp|gif|css|ashx|js|swf).*) $1 [NC,L]


HELP WITH OPTIMIZING
ISSUE #1
Code: Select all
RewriteCond %{HTTP:Host} ^www\.site\.se$ [NC]
RewriteRule .* - [F]

This will give you 403 for particular host.

ISSUE #2
This one will be more like the following:
Code: Select all
RewriteCond %{HTTP_HOST} ^www\.supercoolsite\.dk$ [NC]
RewriteRule (.*) http://www.site.dk/$1 [NC,R=301,L]


Seems like that's all for now.

Regards
Andrew

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 18 guests