Why won't these rules work?

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 5
Joined: 05 Oct 2013, 00:52

Why won't these rules work?

02 Jul 2015, 13:13

URL is http://members.domain.com/members/somefile.htm

RewriteCond %{HTTP_HOST} ^(\w*admin|members|cfajax)\..*$ [NC]
RewriteRule ^(?:/%1)?(.*)$ /%1$1 [L]

%1=members
(?:/%1)? should match "/members" which would cause $1=/somefile.htm
but (?:/%1)? isn't matching "/members"

User avatar
Posts: 5
Joined: 05 Oct 2013, 00:52

Re: Why won't these rules work?

02 Jul 2015, 13:31

I tried the following as well with no success
RewriteCond %{HTTP_HOST} ^(\w*admin|members|cfajax)\..*$ [NC]
RewriteCond %{REQUEST_URI} ^(?:/%1)?(.*)$
RewriteRule ^.*$ /%1%2 [L]

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

Re: Why won't these rules work?

03 Jul 2015, 08:59

Please try the following:

RewriteCond %{HTTP_HOST} ^(admin|members|cfajax)\..*$ [NC]
RewriteCond %{REQUEST_URI} ^/%1(.*)$
RewriteRule .? /%1%2 [L]

If it doesn't work, please clarify which URL this rule should lead to.

And provide rewrite.log records for the test request.

User avatar
Posts: 5
Joined: 05 Oct 2013, 00:52

Re: Why won't these rules work?

04 Jul 2015, 04:16

The point is to have /%1 be optional and stripped off if it is present, but to have the rewrite occur either way.
It worked in version 2 with these rules:
RewriteCond Host: (admin|members|cfajax)\.(?:.*)
RewriteRule (?:/\1)?(.*) /$1$2 [I,L]

User avatar
Posts: 5
Joined: 05 Oct 2013, 00:52

Re: Why won't these rules work?

04 Jul 2015, 04:37

Both http://members.domain.com/members/somefile.htm and http://members.domain.com/somefile.htm should generate a rewrite of /members/somefile.htm.

Basically we use a system that translates subdomains into subfolders, but some of the code is third-party and generates relative links that include the subdomain/subfolder, the rule is meant to prepend the subdomain to the path but also to strip off the matching subfolder if it is present.

It is just a little disappointing that something that was simple in version 2 seems to not work at all in version 3.

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

Re: Why won't these rules work?

06 Jul 2015, 08:07

Ok, thanks for exaplaining the idea.
Let's try to make it working like this:

RewriteCond %{HTTP_HOST} ^(admin|members|cfajax)\..+ [NC]
RewriteRule ^(?:/\1)?(.*) /%1$1 [L]

And if it still doesn't work, please enable logging in httpd.conf by putting:

RewriteLogLevel 9

and provide rewrite.log records for the test request you make.

User avatar
Posts: 5
Joined: 05 Oct 2013, 00:52

Re: Why won't these rules work?

08 Jul 2015, 14:59

Still not working, can't turn on the logging atm though due to traffic making the file explode in seconds, and way to do it for just one site?

My understanding is the rewrite rule regex is checked 1st then the RewriteConds in version 3, which means \1 wouldn't be anything because the RewriteCond hadn't been processed yet.

Also is it normal for error.log to have lines like "[7/8/2015 11:57:22] ISAPI Filter loaded. Version 3.1.0.112. Windows 6.3 (Build 9600 ServicePack:0) ProductType SERVER. CPU type AMD64 NumberOfProcessors 4" every couple of minutes?

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

Re: Why won't these rules work?

09 Jul 2015, 13:16

Hello,

Please try this syntax:

RewriteCond %{HTTP_HOST}#%{REQUEST_URI} ^(admin|members|cfajax)\.[^#]+#.*\1(.*) [NC]
RewriteRule .? /%1%2 [L]

"Also is it normal for error.log to have lines like "[7/8/2015 11:57:22] ISAPI Filter loaded. Version 3.1.0.112. Windows 6.3 (Build 9600 ServicePack:0) ProductType SERVER. CPU type AMD64 NumberOfProcessors 4" every couple of minutes?"
- yes, this is OK

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 25 guests