Question:
Redirect http site to https?
basketball7lc
2009-07-20 09:52:52 UTC
I have a site with the URL (https://www.sitename.com) and it needs a cert to work, so when you go there with http (without the s) you will get an error saying: 'The page must be viewed over a secure channel'. My question is how do I automatically redirect a site from http://www.sitename.com to https://www.sitename.com
Three answers:
flybishop
2009-07-20 10:02:04 UTC
In PHP you'd write it like this:




if ($_SERVER["SERVER_PORT"] != 443)

{

header('Location: https://www.sitename.com');

}

?>
anonymous
2009-07-20 10:13:33 UTC
Easiest way is to create a .htaccess file and have the server do it for you.

The server must allow override on the folder this is in before it can work.



RewriteEngine On

RewriteCond %{SERVER_PORT} !443

RewriteRule (.*) https://www.example.com/require-secure/ [R]
Raja
2009-07-20 10:14:41 UTC
create .htaccess file and add these three lines.



RewriteEngine On

RewriteCond %{HTTP_HOST} !^http://(www\.)?yoursitename.com$ [NC]

RewriteRule ^(.*)$ https://www.yoursitename.com/$1 [L,R=301]



.htaccess file is the outside configuration file for apache


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...