Log in

View Full Version : HTTP to HTTPS redirect advice



theremotedr
01-29-2019, 03:01 PM
Hi,
I have move my site from HTTP to HTTPS and 99% happy when moving to another host.
I am currently still with the old host but havent advised them yet that ive gone with another.


The 1% is the following.
Here is the new HTTPS index page https://www.theremotedoctor.co.uk/index.html & from here you can navigate no problem where links & photos etc work as they should.

If you visit the old url index page http://www.theremotedoctor.co.uk/index.html with a htaccess in place clicking on a drop down or link etc downloads the file as opposed to opening the html page.

If i remove the htaccess file & then click a drop down etc it then opens up the correct item BUT with the HTTPS in the url which is great.

So my issue is the htaccess file causes an issue.
Looking on google etc for items that i sell or services i provide then clicking on an old link etc downloads the file as opposed to opening the page where the redirect should then be doing its job.

Thanks

theremotedr
01-29-2019, 04:30 PM
Hi,
I didnt know but for me it automatically downloads but for others you see a message box like so



6333

BLiZZaRD
01-29-2019, 09:08 PM
Can you post the .htaccess file you are using?

I couldn't reproduce the problem. You should just be forcing HTTPS through .htaccess, no need to worry if a visitor clicks an old link or doesn't add the "s" to the protocol.

theremotedr
01-29-2019, 09:44 PM
Hi,
Since i did this post ive done the following which has now worked.

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?theremotedoctor\.co.uk
RewriteRule ^(.*)$ https://www.theremotedoctor.co.uk/$1 [R,L]



This was my original code file when i was using the http version.
Im not to sure how to add it to this new code without breaking something.


## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
Options Indexes
order deny,allow
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddType application/x-httpd-php .htm .html
AddType video/ogg .ogv
AddType video/mp4 .mp4

BLiZZaRD
01-30-2019, 07:30 PM
Your most likely culprit is this line:



AddType application/x-httpd-php .htm .html


Since you switched hosts, they are probably running a different version. This line tells the server to treat html and htm pages as php pages. What is actually happening though, is the php is trying to be served client-side, resulting in a download instead of an execution.

The AddType is the preferred method, however, some servers run PHP as CGI and the AddType doesn't work, instead you will need AddHandler:



AddHandler application/x-httpd-php .html .htm


The same will go for your video codecs as well. Also note: Some hosts require the AddHandler to specify which version of PHP is being run, so you may need to do something like:



AddHandler application/x-httpd-php5 .html .htm


The best thing to do here is to Google ".htaccess run html as php on {your hosting provider}" It will most likely bring up their knowledge base or a forum that will tell you the exact AddHandler type to use.

The first code you use there forces HTTPS, which is always good. Just throw it at the very top of the rest of the code. :)

~BLiZZ

theremotedr
01-30-2019, 08:45 PM
So yesterday before i added those 4 lines that allowed it to work it was doing this below.

6334

BLiZZaRD
01-31-2019, 12:40 AM
Yeah. That sounds like a problem with the AddType vs AddHandler I mentioned. Switch your AddType lines to AddHandler and it should be fine. :)

theremotedr
01-31-2019, 01:02 AM
Well im struggling with this,
Going by my original code that was is use with the last host,
Then the code in use at present just to have it working,
Then trying to merge them ive come up with this.

AddHandler application/x-httpd-php .html .htm
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?theremotedoctor\.co.uk
RewriteRule ^(.*)$ https://www.theremotedoctor.co.uk/$1 [R,L]
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
Options Indexes
order deny,allow
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddHandler video/ogg .ogv
AddHandler video/mp4 .mp4

Having said that i still get a 403 error advising me i do not have permission to look/edit etc the index file.
The only way at present for me to have it working is this,

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?theremotedoctor\.co.uk
RewriteRule ^(.*)$ https://www.theremotedoctor.co.uk/$1 [R,L]


I dont even know what the old code does but like to put it in and have it there.
The videos etc work fine with it but not sure about other browsers etc.

BLiZZaRD
01-31-2019, 08:40 AM
Save your old htaccess file to your computer and then delete it from your server. Create a brand new one and put this inside:



RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##

<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
Options Indexes
order deny,allow
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddHandler application/x-httpd-php .html .htm
AddType audio/ogg .oga
AddType video/ogg .ogv
AddType application/ogg .ogg
AddHandler application-ogg .ogg .ogv .oga


Save and upload to your server and test. It should be fine. If not, upload the saved one and then let me know.

theremotedr
01-31-2019, 09:58 AM
Morning,
I have left the site so you can see whats going on.

The .htaccess file that was in use was using this code of which i have saved on the pc.
My host is Godaddy


RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?theremotedoctor\.co.uk
RewriteRule ^(.*)$ https://www.theremotedoctor.co.uk/$1 [R,L]

The code that has been uploaded is what you have advised above.

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##

<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
Options Indexes
order deny,allow
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddHandler application/x-httpd-php .html .htm
AddType audio/ogg .oga
AddType video/ogg .ogv
AddType application/ogg .ogg
AddHandler application-ogg .ogg .ogv .oga

Here is the link for my site https://www.theremotedoctor.co.uk/index.html

With that code i see the following error message.

6335

BLiZZaRD
02-01-2019, 08:32 AM
Ahhh... GoDaddy... there is the issue.

They run php through CGI, but they use their own coding. Try this and let me know what happens. If this doesn't work, we will need to get some information from your CPanel log in.



RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Options +ExecCGI
AddHandler application/x-httpd-lsphp .html
AddType audio/ogg .oga
AddType video/ogg .ogv
AddType application/ogg .ogg
AddHandler application-ogg .ogg .ogv .oga

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##

<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
Options Indexes
order deny,allow
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript


We may need to remove your deflate arguments as well. I can't remember if GD allows deflation or not. I will have to research.

theremotedr
02-01-2019, 10:25 AM
Hi,
I have applied & left the code is post #11 now in the htaccess file for you to see etc.
This also did not work.

Also shows same message as before.

Thanks
If i need to go to c panel can you advise path etc so i can get the info you require quickly.

Thanks

BLiZZaRD
02-02-2019, 08:30 AM
Before we do all of that, let's figure out what is breaking the .htaccess file. One or more of the solutions should have already worked, even in GoDaddy.

Start with this and let me know what happens.



RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Options +ExecCGI
AddHandler application/x-httpd-lsphp .html

theremotedr
02-02-2019, 09:50 AM
Hi that worked ok.


RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Options +ExecCGI
AddHandler application/x-httpd-lsphp .html

BLiZZaRD
02-03-2019, 06:12 PM
Just go through and make sure all the other elements of your site work as expected.

I figured most of that was overlay from the previous host, which you probably don't need anymore. If you find that you do, just let me know and we will get the right coding for it.

theremotedr
02-03-2019, 06:24 PM
Hi,
I have been looking around but i dont see any issues,basically what ever i click on etc it does what it is supposed to do.

With respects of the old code i dont know what it did anyway but do you think we should put it in or just leave it as it is ?

Thanks

BLiZZaRD
02-04-2019, 04:37 PM
I wouldn't add anything you don't need.



## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##


Basically, this is a cookie expiry module. Probably left over from a script that was run on the old server. Unless you actually need to control cookies for a particular reason, this can be left out. One example of a requirement would be a sign up pop up. If the user sees the pop up and closes it, the expiry wouldn't show that pop up to them again for XX number of days. It's basically useless except in direct marketing.



<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
Options Indexes
order deny,allow

All this is doing is preventing anyone from directly accessing your .htaccss file. However, with Apache, there is no direct access anyway and most reliable servers will have this encoded in the main file on the whole server. There is no need for it.



<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>


Again, this is probably from the old server. GoDaddy uses FastCGI and the cache modules are already there. This forces them to run again, which can slow down the server or break your site. Either way, if it is already run, you don't need to run it again.



AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript


This is a compression force value for each of the file types. It is used to speed up load times of your site for the client side (visitors). Unless you are running HUGE amounts of scripting and server side cache, implimentation and other such things, the compression won't really matter much. You may leave this out and only suffer a few miliseconds of laod time, which isn't enough to kick anyone off your site because images and scripts aren't loading.



AddType audio/ogg .oga
AddType video/ogg .ogv
AddType application/ogg .ogg
AddHandler application-ogg .ogg .ogv .oga


This allows your site to process and play .ogg files which are native to Linux. The Vorg Obb file format is similar to .wav for windows. If you aren't posting any .ogg files, there isn't a need to have this either. If you are, there are better ways to display them (and you should have mp4 and mp3 back ups running anyway).

If nothing is broken, I would suggest you just leave it as is. Bloat isn't needed. :)

theremotedr
02-04-2019, 06:07 PM
Thanks for your time & effort with this.
I will leave the code which is running at present.

Cheers & have a nice day.

rishimtt
02-06-2019, 04:17 PM
i face problem i open my website he show unprotected but i install HTTPS help me.

Mod Note: rishimtt, Please do not edit this post further.

Davidsmith
02-09-2019, 06:44 AM
How can change in WordPress?

rajputrana
02-10-2019, 07:13 PM
However, on the Outside, shifting from http to https is Very straight forward:

1. Buy an SSL certification,
2. put in your own SSL certification in your own website's hosting accounts,
3. Be certain any internet site backlinks are shifted from http to https so that they really are perhaps not divided once you reverse your https swap, also
4. Setup 301 redirects from HTTP to HTTPS to ensure your web page's addresses have shifted so anyone who's sought a webpage in your own internet site is instantly redirected to the https tackle once you reverse off the change.

GabiJohnson
03-26-2020, 01:46 PM
This was my original code file when i was using the http version.
Im not to sure how to add it to this new code without breaking something.

JoshFerguson
03-27-2020, 04:19 PM
Since you switched hosts, they are probably running a different version. This line tells the server to treat html and htm pages as php pages. What is actually happening though, is the php is trying to be served client-side, resulting in a download instead of an execution.

Cyran
07-21-2020, 09:20 AM
I use the free CloudFlare. You can get an SSL certificate there. It takes 5 minutes to install it.

Amsrong
12-28-2020, 08:27 AM
A 301 redirect is sometimes necessary. If your website has not yet adopted https, Google will give a security prompt when the user visits, which may affect the user's trust in your website.

Tresnase
01-18-2021, 09:41 AM
Redirecting from http to https is really troublesome. Buying ssl certificate directly to install it will sometimes cause unpredictable problems, but it is worth it. Users will not have risk warnings when they come to your website.

moversdubai
01-20-2021, 06:19 AM
Go to Page Rules.

Snap "Make Page Rule"

Enter the URL (put the bullet, so redirection occurs for all the URI)

Snap "Add a Setting" and select "Consistently Use HTTPS" starting from the drop.