Rewrite based on http referer and rewritemap

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Rewrite based on http referer and rewritemap

27 Mar 2013, 23:45

It does repeat three times, but you provided only the first one, while your testing request was supposed to be captured by the third rule?
By the way, do other domains work for other 2 rules? like domain.com and domain.com.uk?

Regards
Andrew

Posts: 13
Joined: 18 Mar 2013, 08:10

Re: Rewrite based on http referer and rewritemap

02 Apr 2013, 06:25

Hi Andrew

None of the domains seem to work for me using a referrer spoof. Here's the full log:

Code: Select all
Wed, 27-Mar-2013  15:02:04 GMT [subdomain.toplevel.org.uk/sid#1863113428][rid#20259936/initial] (2) init rewrite engine with requested uri /test_page.aspx
 Wed, 27-Mar-2013  15:02:04 GMT [subdomain.toplevel.org.uk/sid#1863113428][rid#20259936/initial] (1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
 Wed, 27-Mar-2013  15:02:04 GMT [subdomain.toplevel.org.uk/sid#1863113428][rid#20259936/initial] (1) Htaccess process request e:\www.site.org.uk\.htaccess
 Wed, 27-Mar-2013  15:02:04 GMT [subdomain.toplevel.org.uk/sid#1863113428][rid#20259936/initial] (3) applying pattern '^test_page\.aspx' to uri 'test_page.aspx'
 Wed, 27-Mar-2013  15:02:04 GMT [subdomain.toplevel.org.uk/sid#1863113428][rid#20259936/initial] (4) RewriteCond: input='http://subdomain1.toplevel1.org.uk/test.html' pattern='http://(?:www\.)?([^.]+\.[^.]+).*' => matched
 Wed, 27-Mar-2013  15:02:04 GMT [subdomain.toplevel.org.uk/sid#1863113428][rid#20259936/initial] (5) map lookup FAILED: map=mapfile[txt] key=subdomain1.toplevel1
 Wed, 27-Mar-2013  15:02:04 GMT [subdomain.toplevel.org.uk/sid#1863113428][rid#20259936/initial] (4) RewriteCond: input='NOT_FOUND' pattern='!NOT_FOUND' => not-matched
 Wed, 27-Mar-2013  15:02:04 GMT [subdomain.toplevel.org.uk/sid#1863113428][rid#20259936/initial] (3) applying pattern '^test_page\.aspx' to uri 'test_page.aspx'
 Wed, 27-Mar-2013  15:02:04 GMT [subdomain.toplevel.org.uk/sid#1863113428][rid#20259936/initial] (4) RewriteCond: input='http://subdomain1.toplevel1.org.uk/test.html' pattern='http://(?:www\.)?([^.]+\.[^.]+\.[^.]+).*' => matched
 Wed, 27-Mar-2013  15:02:04 GMT [subdomain.toplevel.org.uk/sid#1863113428][rid#20259936/initial] (5) map lookup FAILED: map=mapfile[txt] key=subdomain1.toplevel1.org
 Wed, 27-Mar-2013  15:02:04 GMT [subdomain.toplevel.org.uk/sid#1863113428][rid#20259936/initial] (4) RewriteCond: input='NOT_FOUND' pattern='!NOT_FOUND' => not-matched
 Wed, 27-Mar-2013  15:02:04 GMT [subdomain.toplevel.org.uk/sid#1863113428][rid#20259936/initial] (3) applying pattern '^test_page\.aspx' to uri 'test_page.aspx'
 Wed, 27-Mar-2013  15:02:04 GMT [subdomain.toplevel.org.uk/sid#1863113428][rid#20259936/initial] (4) RewriteCond: input='http://subdomain1.toplevel1.org.uk/test.html' pattern='http://(?:www\.)?([^.]+\.[^.]+\.[^.]+\.[^.]+).*' => matched
 Wed, 27-Mar-2013  15:02:04 GMT [subdomain.toplevel.org.uk/sid#1863113428][rid#20259936/initial] (5) map lookup FAILED: map=mapfile[txt] key=subdomain1.toplevel1.org.uk/test
 Wed, 27-Mar-2013  15:02:04 GMT [subdomain.toplevel.org.uk/sid#1863113428][rid#20259936/initial] (4) RewriteCond: input='NOT_FOUND' pattern='!NOT_FOUND' => not-matched


Any thoughts?

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

Re: Rewrite based on http referer and rewritemap

02 Apr 2013, 09:59

You see, there're three attempts to search for a key.
For some reason, the third rule includes /test in it, that's the reason it fails. Please, double-check the third rule.

key=subdomain1.toplevel1
key=subdomain1.toplevel1.org
key=subdomain1.toplevel1.org.uk/test


Regards
Andrew

Posts: 13
Joined: 18 Mar 2013, 08:10

Re: Rewrite based on http referer and rewritemap

02 Apr 2013, 10:42

Hi Andrew

I believe that the /test is appearing because the page that the referrer link is http://subdomain1.toplevel1.org.uk/test.html

The rules I have are exactly as you mentioned:

Code: Select all
RewriteCond %{HTTP_REFERER} http://(?:www\.)?([^.]+\.[^.]+).* [NC]
RewriteCond ${mapfile:%1|NOT_FOUND} !NOT_FOUND
RewriteRule ^test_page\.aspx http://www.test.org.uk [NC,R=301,L]

RewriteCond %{HTTP_REFERER} http://(?:www\.)?([^.]+\.[^.]+\.[^.]+).* [NC]
RewriteCond ${mapfile:%1|NOT_FOUND} !NOT_FOUND
RewriteRule ^test_page\.aspx http://www.test.org.uk [NC,R=301,L]

RewriteCond %{HTTP_REFERER} http://(?:www\.)?([^.]+\.[^.]+\.[^.]+\.[^.]+).* [NC]
RewriteCond ${mapfile:%1|NOT_FOUND} !NOT_FOUND
RewriteRule ^test_page\.aspx http://www.test.org.uk [NC,R=301,L]

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

Re: Rewrite based on http referer and rewritemap

02 Apr 2013, 10:59

Not sure I understand:
"I believe that the /test is appearing because the page that the referrer link is http://subdomain1.toplevel1.org.uk/test.html"

Lets try to replace
Code: Select all
RewriteCond %{HTTP_REFERER} http://(?:www\.)?([^.]+\.[^.]+\.[^.]+\.[^.]+).* [NC]

with
Code: Select all
RewriteCond %{HTTP_REFERER} http://(?:www\.)?([^./]+\.[^./]+\.[^./]+\.[^./]+).* [NC]


Regards
Andrew

Posts: 13
Joined: 18 Mar 2013, 08:10

Re: Rewrite based on http referer and rewritemap

19 Apr 2013, 08:55

Thanks for your help Andrew. This worked and the rewrite based on referrer is now in place.

I hope others might find this thread useful.

Previous

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 17 guests