301 redirect for http only

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 5
Joined: 06 Aug 2013, 15:42

301 redirect for http only

06 Aug 2013, 15:50

Hi,
I'm using the example as provided in SEO section of the documentation:

RewriteCond %{HTTPS} (off)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]

However, it's still rewriting the calls to port 443. Can anyone catch what is going on here? I only want traffic on port 80 to go from non www to the www site. Port 443 comes in on a different host on the same domain and not www.

Thanks!
Jason

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

Re: 301 redirect for http only

07 Aug 2013, 03:13

Hello,

I guess in the examples the rule was using
RewriteCond %{HTTPS} (on)?
instead of
RewriteCond %{HTTPS} (off)?
Which is logically directly opposite to what we have here.

Regards
Andrew

User avatar
Posts: 5
Joined: 06 Aug 2013, 15:42

Re: 301 redirect for http only

07 Aug 2013, 07:16

Thanks, but I tried both ways. Any other ideas?

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

Re: 301 redirect for http only

07 Aug 2013, 18:36

The best way is to provide us with the logs.
Logging is described in FAQ - http://www.helicontech.com/forum/10648-FAQ.html

Regards
Andrew

User avatar
Posts: 5
Joined: 06 Aug 2013, 15:42

Re: 301 redirect for http only

08 Aug 2013, 08:52

Thanks. Some more info, I am setting this up on our internal staging server to prove https traffic on 443 will not be rewritten, regardless of URL. We also have http:\\staging2 configured which I would expect the rewrite. Here are the log entries of me attempting to hit 'https:\\staging2' with HTTPS on and off. Thanks again.

[staging2/sid#1630489589][rid#20192920/initial] (2) init rewrite engine with requested uri /eurl.axd/355ab3934992e943adc9402ae3f94cb8/
[staging2/sid#1630489589][rid#20192920/initial] (1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
[staging2/sid#1630489589][rid#20192920/initial] (3) applying pattern '.?' to uri '/eurl.axd/355ab3934992e943adc9402ae3f94cb8/'
[staging2/sid#1630489589][rid#20192920/initial] (4) RewriteCond: input='on' pattern='(off)?' => matched
[staging2/sid#1630489589][rid#20192920/initial] (4) RewriteCond: input='staging2' pattern='^(?!www\.)(.+)$' => matched
[staging2/sid#1630489589][rid#20192920/initial] (4) RewriteCond: input='/eurl.axd/355ab3934992e943adc9402ae3f94cb8/' pattern='(.+)' => matched
[staging2/sid#1630489589][rid#20192920/initial] (1) escaping http://www.staging2/eurl.axd/355ab39349 ... ae3f94cb8/
[staging2/sid#1630489589][rid#20192920/initial] (2) explicitly forcing redirect with http://www.staging2/eurl.axd/355ab39349 ... ae3f94cb8/
[staging2/sid#1630489589][rid#20192920/initial] (2) internal redirect with /eurl.axd/355ab3934992e943adc9402ae3f94cb8/ [INTERNAL REDIRECT]

[staging2/sid#1630489589][rid#20192920/initial] (2) init rewrite engine with requested uri /eurl.axd/355ab3934992e943adc9402ae3f94cb8/
[staging2/sid#1630489589][rid#20192920/initial] (1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
[staging2/sid#1630489589][rid#20192920/initial] (3) applying pattern '.?' to uri '/eurl.axd/355ab3934992e943adc9402ae3f94cb8/'
[staging2/sid#1630489589][rid#20192920/initial] (4) RewriteCond: input='on' pattern='(on)?' => matched
[staging2/sid#1630489589][rid#20192920/initial] (4) RewriteCond: input='staging2' pattern='^(?!www\.)(.+)$' => matched
[staging2/sid#1630489589][rid#20192920/initial] (4) RewriteCond: input='/eurl.axd/355ab3934992e943adc9402ae3f94cb8/' pattern='(.+)' => matched
[staging2/sid#1630489589][rid#20192920/initial] (1) escaping https://www.staging2/eurl.axd/355ab3934 ... ae3f94cb8/
[staging2/sid#1630489589][rid#20192920/initial] (2) explicitly forcing redirect with https://www.staging2/eurl.axd/355ab3934 ... ae3f94cb8/
[staging2/sid#1630489589][rid#20192920/initial] (2) internal redirect with /eurl.axd/355ab3934992e943adc9402ae3f94cb8/ [INTERNAL REDIRECT]

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

Re: 301 redirect for http only

08 Aug 2013, 15:21

Hmmm... maybe it's too late at night and I didn't get something, but what's the issue? Https should be redirected to https, and httpd to http AND append http://WWW., right? Right?
I see the following parts and it seems that everything works as expected:

Code: Select all
(4) RewriteCond: input='on' pattern='(off)?' => matched
(2) explicitly forcing redirect with http://www.staging2/eurl.axd/355ab39349 ... ae3f94cb8/
and
Code: Select all
(4) RewriteCond: input='on' pattern='(on)?' => matched
(2) explicitly forcing redirect with https://www.staging2/eurl.axd/355ab3934 ... ae3f94cb8/

Regards
Andrew

User avatar
Posts: 5
Joined: 06 Aug 2013, 15:42

Re: 301 redirect for http only

08 Aug 2013, 15:47

no, you are correct. I'm not attempting or do I want to re-direct any protocols. It is indeed staying within protocol with HTTPS (on), my issue is that I don't want anything coming in on port 443 to have its URL rewritten, only port 80. Hope that makes sense.

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

Re: 301 redirect for http only

09 Aug 2013, 01:28

Well, it doesn't yet. Or maybe it's just me... and I need some sleep

HTTPS URLs begin with "https://" and use port 443 by default, whereas HTTP URLs begin with "http://" and use port 80 by default.


HTTPS is by default 443 port, so maybe you could provide an example.

Regards
Andrew

User avatar
Posts: 5
Joined: 06 Aug 2013, 15:42

Re: 301 redirect for http only

09 Aug 2013, 08:00

OK, let me try to explain it this way:

1) If the user types 'https:\\' and then anything at all as the address, I don't want ISAPI_Rewriter to do anything...no changing, no redirecting, no nothing.

2) If the user types 'http:\\' and the next 3 characters are not www, then I want to re-write the url to prepend www.

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

Re: 301 redirect for http only

12 Aug 2013, 03:10

In this case lets try:

Code: Select all
RewriteCond %{HTTPS} !^on
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http://www.%2%3 [R=301,L]


If not https, not www, than redirect to http://www....
We don't mention https at all.

Regards
Andrew

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 20 guests