https to http

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 7
Joined: 04 Apr 2013, 18:11

https to http

04 Aug 2013, 17:04

Hello,

I have been searching for a script that redirects https to http when not on https pages defined. I have been searching through searching the community and example I haven't found one that works.


Below is what I have been trying but it's only for http to https. I need the opposite and then the ability to add specific URLs that should be https.
http://www.helicontech.com/forum/13114- ... HTTPS.html

I found this one, but how do I add exceptions?
# redirect all https requests to http
RewriteCond %HTTPS (?!off).*
RewriteCond Host: (.*)
RewriteRule (.*) http\://$1$2 [I,RP]

Another from the example page
#Redirect HTTPS to non-HTTPS
RewriteCond %{HTTP:Host} (.*)
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} (.*)
RewriteRule .? http://%1%2 [R,L]

Thanks,
Jobu

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

Re: https to http

05 Aug 2013, 10:48

Hello, Jobu

Do you mean you want to specify specific URLs to stay https?
Please try to do it like this:

# redirect all https requests to http
RewriteCond %{HTTPS} ^(?!off).*
RewriteCond %{HTTP_HOST} (.*)
RewriteCond %{REQUEST_URI} !^/url_to_stay_https [NC]
RewriteRule (.*) http\://$1$2 [R=301,L]

User avatar
Posts: 7
Joined: 04 Apr 2013, 18:11

Re: https to http

05 Aug 2013, 13:08

Hello Anton,

Thank you for your quick response. Yes, I am trying to specify specific URLs to stay https. However, is there also command that will specify specific URLs to stay https and reset other back to http when outside of the specific ones?

Note: The issue is users are hitting the https and then surfing other pages as https, when they should be http.

Thank you,
Jobu

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

Re: https to http

07 Aug 2013, 03:21

What you can do with Anton's rule is edit the condition he offered as the following:

Code: Select all
RewriteCond %{REQUEST_URI} !^/(?:url_to_stay_https|otherURL|folder/file|folder1/folder2/file1|severalMoreURLs) [NC]


How many pages do you need?

Regards
Andrew

User avatar
Posts: 7
Joined: 04 Apr 2013, 18:11

Re: https to http

07 Aug 2013, 10:45

Andrew,

I made the change but I am not seeing any results.
Thanks for asking. I only have about five URLs.

Here is the code I am using:
# redirect all https requests to http
RewriteCond %{HTTPS} ^(?!off).*
RewriteCond %{HTTP_HOST} (.*)
RewriteCond %{REQUEST_URI} !^/(?:url_to_stay_https|/folder1/page.aspx|/folder2/page.aspx|/folder3/page.aspx|/folder4/page.aspx|/folder5/page.aspx) [NC]
RewriteRule (.*) http\://$1$2 [R=301,L]


Here is another one I found:
# rule 1b: prepend www to the hostname, when it is not present.
RewriteCond %{HTTP_HOST} ^(?!www\.).*website\.com$
RedirectRule ^/(.*)$ http://www.website.com/$1 [R=301]

# rule 2: exclude a few pages from any IIRF rules that appear below this one,
# including in particular the https-to-http redirection rule. The replacement
# string of dash (-) tells IIRF to "do nothing". The rule decorated with the [L]
# (last) modifier to tell IIRF - no more rules processing for this request.
RewriteRule ^/folder1/page.aspx - [L]
RewriteRule ^/folder2/page.aspx - [L]
RewriteRule ^/folder3/page.aspx - [L]
RewriteRule ^/folder4/page.aspx - [L]
RewriteRule ^/folder5/page.aspx - [L]


# rule 3: redirect to http if https is in use
RewriteCond %{SERVER_PORT} ^443$
RedirectRule ^/(.*)$ http://www.website.com/$1 [R=301]

Best,
Jobu

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

Re: https to http

07 Aug 2013, 18:41

Let's try to leave only the combination we've provided and enable logging.
Please, provide rewrite.log for a testing request. Logging issues are desribed in FAQ - http://www.helicontech.com/forum/10648-FAQ.html

Regards
Andrew

User avatar
Posts: 7
Joined: 04 Apr 2013, 18:11

Re: https to http

09 Aug 2013, 12:17

Andrew, thank you for your response. I will stick with what you suggested. I will submit my rewrite.log. Could you confirm the script that I have posted that lists my https exceptions, looks OK structurally?

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

Re: https to http

12 Aug 2013, 03:05

Yes, the syntax is okay.

Regards
Andrew

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 15 guests