Regex Pattern Matching bug in my rewrite

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

Regex Pattern Matching bug in my rewrite

20 Nov 2013, 23:16

Hey Guys,

Please help, I'm tipping this issue is due to my intermediate understanding of regex ( I usually get by fine ).

I have the following rule in my .htaccess

RewriteCond %{HTTP_HOST} ^([edith\.|bertha\.]*)([visual|performing|screen|architecture|design|publishing]+)\.sitename(.+)/? [NC]
RewriteRule ^$ /${mapfile_domains:%3}/section-%2.aspx?SectionId=${mapfile_sections:%2} [L]

This examples works fine:
edith.performing.sitename.com it does an internal redirect to the page 'section-performing.aspx?SectionId=x'
edith.visual.sitename.com it does an internal redirect to the page 'section-visual.aspx?SectionId=x'
edith.publishing.sitename.com it does an internal redirect to the page 'section-publishing.aspx?SectionId=x'

However If I go to 'architecture'
edith.architecture.sitename.com it writes to 'section-rchitecture.aspx?SectionId=x' (The 'a' in architecture is dropped??)

If I go to 'design'
edith.design.sitename.com it writes to 'section-sign.aspx?SectionId=x' (The 'de' in design is dropped??)

Can anyone tell me where my stupidity lies...

Errol (^_^)

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

Re: Regex Pattern Matching bug in my rewrite

21 Nov 2013, 00:37

I'm tipping however that is has something to do with 'edith' containing 'de' which is then negated in my rewrite rule for 'design'
And 'bertha' containing 'a' which is then negated in my rewrite rule for 'architecture'

Am I close???

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

Re: Regex Pattern Matching bug in my rewrite

21 Nov 2013, 01:29

Haha, I've fixed my own problem, realising my error...

I removed the [] which makes the words literals (Doh)

The rule is now

RewriteCond %{HTTP_HOST} ^(edith\.|bertha\.)*(visual|performing|screen|architecture|design|publishing)+\.sitename(.+)/? [NC]
RewriteRule ^$ /${mapfile_domains:%3}/section-%2.aspx?SectionId=${mapfile_sections:%2} [L]

I hope this helps someone else that has made the same mistake.

Errol (^_^)

User avatar
Posts: 1
Joined: 19 Dec 2014, 03:24

Re: Regex Pattern Matching bug in my rewrite

19 Dec 2014, 03:28

Thanks this helps.

These examples are for the entire site, but how can I apply these rules to a single web page?

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

Re: Regex Pattern Matching bug in my rewrite

04 Jan 2015, 19:56

If you wanted to apply this to a single page, you would mention the page in the RewriteRule

If the page was 'shop/televisions/my-television.html'

RewriteCond %{HTTP_HOST} ^(edith\.|bertha\.)*(visual|performing|screen|architecture|design|publishing)+\.sitename(.+)/? [NC]
RewriteRule ^shop/televisions/my-television\.html$ /${mapfile_domains:%3}/section-%2.aspx?SectionId=${mapfile_sections:%2} [L]

Errol :)

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 11 guests