Consecutive RewriteRule (conversion by 2.0 ver)

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 6
Joined: 02 May 2013, 04:30

Consecutive RewriteRule (conversion by 2.0 ver)

02 May 2013, 04:40

I'v convert from ISAPI 2.x ti Isapi 3.x with our tools.

I'v theese new (not working) rules (my rules are more complex, but i'v simpilfied):

RewriteCond %{HTTP:Host} ^(?:.*)\.domain\..*$
RewriteCond %{REQUEST_URI} ^/test$
RewriteRule .* /page.htm

RewriteCond %{HTTP:Host} ^(?:.*)\.domain\..*$
RewriteCond %{REQUEST_URI} ^/page.htm$
RewriteRule .* /newpage.htm

First step: /test > page.htm
Second step: /page.htm > /NewPage.htm

Second RewriteCond refer to "original" RequestUri, not to rewritten URI.

OLD Rules (2.x) was in this format, and work fine:
RewriteCond Host: (?:.*)\.domain\..*
RewriteCond URL /url
RewriteRule .* /page.htm


can you help me, please ?



regards
Marco Li Mandri

User avatar
Posts: 6
Joined: 02 May 2013, 04:30

Re: Consecutive RewriteRule (conversion by 2.0 ver)

04 May 2013, 03:39

Hi, have you read my post ?

thank you,
best regards
Marco Li Mandri

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

Re: Consecutive RewriteRule (conversion by 2.0 ver)

05 May 2013, 18:51

Are you looking for rewrite or redirect?

Regards
Andrew

User avatar
Posts: 6
Joined: 02 May 2013, 04:30

Re: Consecutive RewriteRule (conversion by 2.0 ver)

06 May 2013, 10:58

Only Rewrite.

End user type "www.domain.com/page"

First rewrite transform URL in www.domain.com/section/typecontent.chtm

Second series of rewrite rule trasform every *.chtm in real page page.aspx?parameter...

For this reason i nedd 2 consecutive REWRITE.

Thank you
Best regards
MLM

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

Re: Consecutive RewriteRule (conversion by 2.0 ver)

06 May 2013, 11:13

I would try:

Code: Select all
RewriteCond %{HTTP:Host} ^(?:[^.]+\.)?domain\..*$
RewriteCond %{REQUEST_URI} ^/test$ [NC]
RewriteRule .* /page.htm

RewriteCond %{HTTP:Host} ^(?:[^.]+\.)?domain\..*$
RewriteCond %{REQUEST_URI} ^/page\.htm$ [NC]
RewriteRule .* /newpage.htm


However, based on what I understood, you may want to use HTTP_X_REWRITE_URL instead of REQUEST_URI in the second rule. The meaning of this variable is described here - http://www.helicontech.com/isapi_rewrite/doc/concept.htm.

Another useful feature in ISAPI_Rewrite 3 is the logs. We can enable logging (described in FAQ - http://www.helicontech.com/forum/10648-FAQ.html) and see the way the request is being processed in rewrite.log.

Regards
Andrew

User avatar
Posts: 6
Joined: 02 May 2013, 04:30

Re: Consecutive RewriteRule (conversion by 2.0 ver)

07 May 2013, 07:00

HTTP_X_REWRITE_URL contains value of URL before modification.
I Need value AFTER modification, but REQUEST_URI contain original value instead rewritten value, every.

I've enabled rewritelog.
I've tested theese rules (on Win 2012 Server):

------------------

RewriteCond %{HTTP:Host} ^(?:.*)\.negozioelettronico\..*$
RewriteCond %{REQUEST_URI} ^/test$
RewriteRule .* /page\.htm

RewriteCond %{HTTP:Host} ^(?:.*)\.negozioelettronico\..*$
RewriteCond %{REQUEST_URI} ^/page\.htm$
RewriteRule .* /newpage.htm

RewriteCond %{HTTP:Host} ^(?:.*)\.negozioelettronico\..*$
RewriteCond %{HTTP_X_REWRITE_URL} ^/page\.htm$
RewriteRule .* /newpage.htm

RewriteCond %{HTTP:Host} ^(?:.*)\.negozioelettronico\..*$
RewriteCond %{URL} ^/page\.htm$
RewriteRule .* /newpage.htm


-----------

First RULE work Fine, after First RULE the variable "REQUEST_URI" remain with Original VALUE, and REQUEST_URI have same value of HTTP_X_REWRITE_URL.

(3) applying pattern '.*' to uri '/test'
(4) RewriteCond: input='srcdemo.negozioelettronico.it' pattern='^(?:.*)\.negozioelettronico\..*$' => matched
(4) RewriteCond: input='/test' pattern='^/test$' => matched
(1) Rewrite URL to >> /page.htm
(2) rewrite '/test' -> '/page.htm'

(3) applying pattern '.*' to uri '/page.htm'
(4) RewriteCond: input='srcdemo.negozioelettronico.it' pattern='^(?:.*)\.negozioelettronico\..*$' => matched
(4) RewriteCond: input='/test' pattern='^/page\.htm$' => not-matched <<<<<<<<<<<<<<<<<<<<<<<<<< should be value of "input" variable set to "page.htm" ?
May be a bug or misconfiguration ?

(3) applying pattern '.*' to uri '/page.htm'
(4) RewriteCond: input='srcdemo.negozioelettronico.it' pattern='^(?:.*)\.negozioelettronico\..*$' => matched
(4) RewriteCond: input='/test' pattern='^/page\.htm$' => not-matched

(3) applying pattern '.*' to uri '/page.htm'
(4) RewriteCond: input='srcdemo.negozioelettronico.it' pattern='^(?:.*)\.negozioelettronico\..*$' => matched
(4) RewriteCond: input='/test' pattern='^/page\.htm$' => not-matched


regards
MLM

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

Re: Consecutive RewriteRule (conversion by 2.0 ver)

07 May 2013, 11:43

Tanks for this one... we need to test in our environment. What build are you using? And what is the version of your IIS?

User avatar
Posts: 6
Joined: 02 May 2013, 04:30

Re: Consecutive RewriteRule (conversion by 2.0 ver)

08 May 2013, 04:47

Win Server 2012
IIS 8.0.9200.16384
Isapi Rewrite 3.1.0.99

File .htaccess with this configuration

RewriteEngine On
RewriteCompatibility2 On <<< don't work with or without this
RepeatLimit 8
RewriteBase

RewriteCond %{HTTP:Host} ^(?:.*)\.negozioelettronico\..*$
RewriteCond %{REQUEST_URI} ^/test$
RewriteRule .* /page\.htm

RewriteCond %{HTTP:Host} ^(?:.*)\.negozioelettronico\..*$
RewriteCond %{REQUEST_URI} ^/page\.htm$
RewriteRule .* /newpage.htm

thanks

regards
MLM

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

Re: Consecutive RewriteRule (conversion by 2.0 ver)

08 May 2013, 09:11

This is specifics of ISAPI_Rewrite 3, please, see http://www.helicontech.com/articles/exploding-myths-about-mod_rewrite-part-i/ and http://www.helicontech.com/articles/exploding-myths-about-mod_rewrite-part-2/ to understand the logic behind it.

Regards
Andrew

User avatar
Posts: 6
Joined: 02 May 2013, 04:30

Re: Consecutive RewriteRule (conversion by 2.0 ver)

08 May 2013, 15:47

this means that ISAPI 2 works differently from ISAPI 3?

there is not a variable that contains "rewritten REQUEST_URI" ?

there is a solution to get the same behavior of ISAPI 2 using ISAPI 3 ?

regards
MLM

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

Re: Consecutive RewriteRule (conversion by 2.0 ver)

13 May 2013, 07:27

Hello,

Please try to use the following config in ISAPI_Rewrite 3 to achieve what you want:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^.*\.negozioelettronico\.
RewriteRule ^test$ /page.htm [NC]

RewriteCond %{HTTP_HOST} ^.*\.negozioelettronico\.
RewriteRule ^page\.htm$ /newpage.htm [NC]

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 16 guests