Forum Moderators: phranque

Message Too Old, No Replies

rewrite http to https

         

glimbeek

2:29 pm on Jan 22, 2010 (gmt 0)

10+ Year Member



I want to rewrite all https:// url's to http://

After searching on Google and this forum I found the following post:
[webmasterworld.com...]

mikemwe uses the following code:

RewriteEngine on
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ [mysite.com...] [R,L]

To rewrite all https:// url's to http://

Is this method full proof? I have no use for making certain folders secure or anything like that. I just don't want any https:// url's.

And how about using R=301 instead of R?

Google has already indexed some https links even though I don't use any https links on my site.

dmwaff

4:11 pm on Jan 22, 2010 (gmt 0)

10+ Year Member




Something to think about is you lose POST data on redirect. You can use the following in your HTTP main or virutal host container. This is not depended on 443 being your SSL bind port. If you are behind a Load Balancer doing port forwarded to a higher port for SSL (4443 for example).

Ignore LB keepalive HEAD/GET requests on incoming (optional).

You'll get better performance if you match on the first character "." and pass the REQUEST_URI instead of eval'ing the entire URL .*, buffer ( ) and substitute as $1. You are grabbing and processing every request (.*) anyway so just stop processing on the first character match and apply condition and rule.

RewriteCond %{REQUEST_URI} !/keepalive\.html
RewriteRule . [%{HTTP_HOST}%{REQUEST_URI}...] [L]

David

glimbeek

9:16 am on Jan 27, 2010 (gmt 0)

10+ Year Member



I found the following:

RewriteEngine On
RewriteCond %{HTTPS} =on [OR]
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

Should this work?

[edited by: jdMorgan at 3:16 pm (utc) on Jan. 27, 2010]
[edit reason] Example.com [/edit]

g1smd

9:30 am on Jan 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Have you tried it and examined the server headers using Live HTTP Headers or similar?

glimbeek

11:27 am on Jan 28, 2010 (gmt 0)

10+ Year Member



I haven't tried it because I don't want to test it on my live server.

And what do you mean by: "examined the server headers using Live HTTP Headers or similar" ?

jdMorgan

2:12 pm on Jan 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Search for "Live HTTP Headers" in quotes. This is an add-on for Firefox and other Mozilla-based browsers. This add-on (or something similar) is basic Webmaster kit.

Add exclusions to the code to disable it unless the request comes from your own IP address. Then, as long as there are no "fatal" syntax errors in the code, you can test on your live server with no impact to regular visitors. Just precede each rule with
RewriteCond %{REMOTE_ADDR} =192.168.0.2
replacing that IP address with your real IP address. This prevents the code from running unless the request comes from *exactly* your own IP address. If you're on a dynamic IP address, then you can probably make it work better by omitting the last octet of the IP address, as in
RewriteCond %{REMOTE_ADDR} ^192\.168\.0\.
This will make the code more forgiving if the last octet of your IP address changes frequently, but it will also allow the code to run if anyone requests your site from the same ISP subnet that you are assigned to (which is not terribly likely, but possible).

If you cannot test on your live server -- say by defining and testing in a 'test' subdomain, then you need to set up a test server. While this may take several days (or even more, the first time), it will save you a lot of time and headaches in the future. Or you could rent a separate server just for testing from the same host -- or at least one that is set up identically to your 'real' server.

The code above appears to be sound -- if a bit redundant; only the second RewriteCond should be needed. But if you can't/won't test it, then anything you read here is just an opinion, and you're at an impasse.

I would recommend that you either invest the time in learning enough about Apache so that you can read and understand this kind of code with confidence, or do not use such code at all. This is server configuration code, and it is dangerous to put such code on your server if you you don't understand it and cannot modify it and/or maintain it. Not only must it be syntactically correct, but it must do exactly what you want it to do; Understanding what it does with URL requests and what the 'side effects' of its actions will be with regard to both visitors and search ranking are both critically important.

The preceding statement is not meant to be harsh, but rather a simple statement of reality. It is offered with your best interests in mind. Our Forum Charter contains links to some resources to help you get started.

Jim

glimbeek

1:27 pm on Feb 1, 2010 (gmt 0)

10+ Year Member



jdMorgan,

Thank you for your great reply, I'm testing this at the moment and it seems to be going OK.

George