Not detecting domain extension in pattern

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 8
Joined: 07 Sep 2012, 03:04

Not detecting domain extension in pattern

15 Apr 2014, 21:45

Hi,

I have a rule that works perfectly well on our site for all users, however for one of our larger members (a university) whom use a proxy domain to access our system, the rules fails..
Some large members like these are logged in automatically to our website by their IP address for students on their network or using their student portal. Hence the use of the proxy.

So typically the Url would be: http://subdomain1.sitename.com.au
The Rule is:
RewriteCond %{HTTP_HOST} ^(subdomain1|subdomain2|subdomain3).sitename(.+)/? [NC]
RewriteRule ^$ /${mapfile_domains:%3}/page-%2.aspx?subId=${mapfile_subdomains:%2} [L]

So ultimately the resulting uri passed to IIS is:
/au/page-subdomain1.aspx?subId=x

So when the University uses their proxy to initially access our site, rather than the url looking like this:
http://subdomain1.sitename.com.au
It looks like this:
http://subdomain1.sitename.com.au.ezp.lib.universityname.edu.au

They end up with a 404 and get
Requested Url: /page-subdomain1.aspx?subId=x
However IIS actually needs '/au/page-subdomain1.aspx?subId=x'

The problem as you can see is that the domain extension for the 3rd pattern %3 to get the /au/ part of the Uri to send to IIS fails.
mapfile_domains contains
.com.au au
.co.uk uk
.com us
.de de
.co.nz nz
.com.tw tw
.cn cn

I know I could add to the map file
.com.au.ezp.lib.universityname.edu.au au

However I would rather make it cleaner like this (fyi only .com.au needs to access this):
RewriteCond %{HTTP_HOST} ^(subdomain1|subdomain2|subdomain3).sitename(\.com\.au)(.*)/? [NC]
RewriteRule ^$ /${mapfile_domains:%3}/page-%2.aspx?subId=${mapfile_subdomains:%2} [L]

I would have expected (.*) on the end of the RewriteCond would have picked up '.ezp.lib.universityname.edu.au'

Can anyone see what I have missed or where I've gone wrong... I'm desperate for help.

Thanks heaps

Errol :)

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

Re: Not detecting domain extension in pattern

16 Apr 2014, 05:30

Hello,

I wonder why you are referring to %3 when it will match against (.*) and as far as I understand, you need to look for (\.com\.au) in mapfile_domains. Correct me if I'm wrong.

I suggest you to fix your rules like this:

RewriteCond %{HTTP_HOST} ^(subdomain1|subdomain2|subdomain3)\.sitename(\.com\.au) [NC]
RewriteRule ^$ /${mapfile_domains:%2}/page-%1.aspx?subId=${mapfile_subdomains:%1} [L]

User avatar
Posts: 8
Joined: 07 Sep 2012, 03:04

Re: Not detecting domain extension in pattern

16 Apr 2014, 22:18

Hey Anton,

Thanks for this. However, my bad, thats not the problem..
I had actually removed an irrelevant part of the RewriteCond for the post (it was %3) however you are correct, the rule in my post should be %2 due to my alteration...

Looking at your suggestion:
RewriteCond %{HTTP_HOST} ^(subdomain1|subdomain2|subdomain3)\.sitename(\.com\.au) [NC]
RewriteRule ^$ /${mapfile_domains:%2}/page-%1.aspx?subId=${mapfile_subdomains:%1} [L]

The issue is still that the users proxy domain turns the url into
http://subdomain1.sitename.com.au(.ezp.lib.universityname.edu.au)


Here is the actual full rule from our site. I had previously removed the testServer stuff to simplify it for the post.
The rule is for use on both our UAT and Production servers:

# 'Rule updated to handle Eziproxy urls for IP Licences
RewriteCond %{HTTP_HOST} ^(testServer1\.|testServer2\.)*(subdomain1|subdomain2|subdomain3)\.sitename(\.com\.au)(.*)/? [NC]
RewriteRule ^$ /${mapfile_domains:%3}/page-%2.aspx?subId=${mapfile_subdomains:%2} [L]

They end up with a 404 and get
Requested Url: /page-subdomain1.aspx?subId=x
Rather than '/au/page-subdomain1.aspx?subId=x'

Thanks again

Errol :)

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

Re: Not detecting domain extension in pattern

21 Apr 2014, 06:02

Hello, Errol

Let's try it in a little different way:

# 'Rule updated to handle Eziproxy urls for IP Licences
RewriteCond %{HTTP_HOST} ^(testServer1\.|testServer2\.)*(subdomain1|subdomain2|subdomain3)\.sitename(\.com\.au) [NC]
RewriteProxy ^$ http://%2.sitename.com.au/${mapfile_domains:%3}/page-%2.aspx?subId=${mapfile_subdomains:%2} [L]

If it doesn't work please specify the initial requested URL and the desired resulting URL once again.

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 11 guests