Rewrite rules failing under IIS8.0 / Win 2012

ISAPI_Rewrite is a powerful URL manipulation engine based on regular expressions
User avatar
Posts: 3
Joined: 27 Oct 2013, 08:05

Rewrite rules failing under IIS8.0 / Win 2012

27 Oct 2013, 08:17

Hi there,

This rule below worked on all our sites for 5 years under ISAPI_Rewrite2 on Windows 2008 Server 64 bit on IIS7.5

# Rewrite the domain to begin with so always have www. prefix for SSL
RewriteCond Host: ([^.]+\.com.au)
RewriteRule (.*) http\://www\.$1$2 [I,RP]

Recently we have move to Windows Server 2012 running IIS8.0 and we get HTTP errors on the site when this condition is run. The site works fine if accessed via http://www.domain.com, but when run as domain.com without the "www" it throws an exception?

Is there anything I can do to get this working under IIS8 / Win 2012?

Cheers
Phil

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Rewrite rules failing under IIS8.0 / Win 2012

28 Oct 2013, 06:51

The problem may be due to incorrect mappings in IIS, it's unlikely to be caused by ISAPI_Rewrite.
Please try to disable ISAPI_Rewrite and make a request to non-www and make sure the error does not persist.
It would also be helpful if you described the error in more details or provided its screenshot.
Also, you can you Failed request tracing tool in IIS to log everything that happens upon request and it's easier to see on which stage the problem occurs.

User avatar
Posts: 3
Joined: 27 Oct 2013, 08:05

Re: Rewrite rules failing under IIS8.0 / Win 2012

30 Oct 2013, 23:20

Hi Anton,

I've checked the IIS8 logs and this is what is appearing during requests to the non "www" domain.

2013-10-31 02:14:43 216.15.209.149 GET / - 80 - 150.101.157.75 Mozilla/5.0+(Macintosh;+Intel+Mac+OS+X+10_8_5)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/30.0.1599.101+Safari/537.36 - 200 0 0 405

So for example:

http://www.flycookie.com works fine, however accessing http://flycookie.com results in a HTTP error when the Rewrite rule is run. If i comment out this rule in the httpd.ini the domain loads fine at http://flycookie.com.

So it's definitely something to do with that rule, and every other rule in the httpd.ini seems to work fine since the migration it's only these domain rewrite rules that are failing.

Also i disabled ISAPI_Rewrite and the domain with and without the www worked fine.

Cheers
Phil

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Rewrite rules failing under IIS8.0 / Win 2012

01 Nov 2013, 05:41

Hello, Phil

If this is the rule that is causing issues

RewriteCond Host: ([^.]+\.com.au)
RewriteRule (.*) http\://www\.$1$2 [I,RP]

and this is the request that fails because of this rule: http://flycookie.com
than it's really weird as this rule doesn't even match that request - it's waiting for .com.au and .com is requested.
Do you have other domain rewrite rules?
Could you show your complete config for investigation.

User avatar
Posts: 3
Joined: 27 Oct 2013, 08:05

Re: Rewrite rules failing under IIS8.0 / Win 2012

01 Nov 2013, 12:12

Apologies Anton i pasted the wrong rule that was from another site with the same issue that does end in .com.au

The http://flycookie.com rule is:

RewriteCond Host: ([^.]+\.com)
RewriteRule (.*) http\://www\.$1$2 [I,RP]

We basically just picked up all these sites which had been working for 5 years without a hitch and dropped them onto a new hosting environment running IIS8.0 and Windows 2012 Server. No other difference and all other rewrite rules work. I've pasted the full config file for flycooki.com below


[ISAPI_Rewrite]

# 3600 = 1 hour
CacheClockRate 3600

RepeatLimit 32

# Block external access to the httpd.ini and httpd.parse.errors files
RewriteRule /httpd(?:\.ini|\.parse\.errors).* / [F,I,O]
# Block external access to the Helper ISAPI Extension
RewriteRule .*\.isrwhlp / [F,I,O]


# Rewrite the domain to begin with so always have www. prefix for SSL
RewriteCond Host: ([^.]+\.com)
RewriteRule (.*) http\://www\.$1$2 [I,RP]

# Common
RewriteRule /(.*)/includes/behaviors/(.*) /includes/behaviors/$2 [I,L]
RewriteRule /(.*)/images/blank.gif(.*) /images/blank.gif [I,L]

# Checkout
RewriteRule /checkout/step_(\w+)/index.htm /index.cfm\?page=checkout\&step=$1 [I,U,L]
RewriteRule /checkout/status_(\w+)/index.htm /index.cfm\?page=checkout\&status=$1 [I,U,L]

# Campaign
RewriteRule /campaign/id_(\w+)/index.htm /index.cfm\?page=campaign\&id=$1 [I,U,L]

# Signup
RewriteRule /signup/status_(\w+)/index.htm /index.cfm\?page=signup\&status=$1 [I,U,L]

# MyAccount
RewriteRule /myaccount/status_(\w+)/index.htm /index.cfm\?page=myaccount\&status=$1 [I,U,L]

# Shop
RewriteRule /shop/(\w+)/index.htm /index.cfm\?page=shop\&productcategoryalias=$1 [I,U,L]
RewriteRule /shop/(\w+)/(\w+)/index.htm /index.cfm\?page=shop\&productcategoryalias=$1\&productid=$2 [I,U,L]

# Media Gallery
RewriteRule /mediagallery/(\w+)/index.htm /index.cfm\?page=mediagallery\&category=$1 [I,U,L]

#Blog
RewriteRule /blog/index.htm /index.cfm\?page=blog\&action=page [I,U,L]
RewriteRule /blog/page/(\d+)/index.htm /index.cfm\?page=blog\&action=page\&pageNo=$1 [I,U,L]
RewriteRule /blog/search/index.htm /index.cfm\?page=blog\&action=search [I,U,L]
RewriteRule /blog/category/([A-Za-z0-9\-]+)/index.htm /index.cfm\?page=blog\&action=category\&categoryalias=$1 [I,U,L]
RewriteRule /blog/(\d+)/(\d+)/(\d+)/([A-Za-z0-9\-_]+)/index.htm /index.cfm\?page=blog\&year=$1\&month=$2\&day=$3\&articleAlias=$4 [I,U,L]
RewriteRule /blog/(\d+)/(\d+)/(\d+)/([A-Za-z0-9\-_]+)/index.htm(.*) /index.cfm\?page=blog\&year=$1\&month=$2\&day=$3\&articleAlias=$4\&(.*) [I,U,L]
RewriteRule /blog/(\d+)/(\d+)/(\d+)/index.htm /index.cfm\?page=blog\&year=$1\&month=$2\&day=$3 [I,U,L]
RewriteRule /blog/(\d+)/(\d+)/index.htm /index.cfm\?page=blog\&year=$1\&month=$2 [I,U,L]

# News
RewriteRule /news/year_(\w+)/month_(\w+)/index.htm /index.cfm\?page=news\&year=$1\&month=$2 [I,U,L]
RewriteRule /news/year_(\w+)/month_(\w+)/article_(\w+)/index.htm /index.cfm\?page=news\&year=$1\&month=$2\&id=$3 [I,U,L]
RewriteRule /news/year_(\w+)/month_(\w+)/article_(\w+)/index.htm(.*) /index.cfm\?page=news\&year=$1\&month=$2\&id=$3\&(.*) [I,U,L]
RewriteRule /news/unsubscribe=([A-Za-z0-9=\&\-_@.,]+) /index.cfm\?page=news&unsubscribe=$1 [I,U,L]
RewriteRule /newsubscribe/index.htm /index.cfm\?page=newsubscribe [I,U,L]

# Competiton
RewriteRule /competition/competition_(\w+)/index.htm /index.cfm\?page=competition\&id=$1 [I,U,L]

# RSS
RewriteRule /rss /rss.cfm\?id=1 [I,U,L]

# Team
RewriteRule /team/category_(\w+)/index.htm /index.cfm\?page=team\&categoryid=$1 [I,U,L]
RewriteRule /team/category_(\w+)/id_(\w+)/index.htm /index.cfm\?page=team\&categoryid=$1\&id=$2 [I,U,L]

# Site-wide rules
RewriteRule /index.htm /index.cfm [I,U,L]
RewriteRule /(\w+)/index.htm /index.cfm\?page=$1 [I,U,L]
RewriteRule /(\w+)/(\w+)/index.htm /index.cfm\?page=$1\&subpage=$2 [I,U,L]
RewriteRule /(\w+)/(\w+)/(\w+)/index.htm /index.cfm\?page=$1\&subpage=$2\&subsubpage=$3 [I,U,L]



Cheers
Phil

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Rewrite rules failing under IIS8.0 / Win 2012

04 Nov 2013, 08:03

Hello, Phil

Thanks for providing the config.
It's still unclear what is wrong with this rule.
So I have to ask you again to try and get us the log from Failed request tracing tool in IIS.
It does provide a bunch of valuable information and may tell a lot about what happens to the request.
Also please make sure that you don't have ISAPI_Rewrite registered twice - on server and site level. It should only be registered on server level.

Return to ISAPI_Rewrite 2.x

Who is online

Users browsing this forum: No registered users and 0 guests