Most of ecommerce websites, online shopping websites and secure websites uses SSL or https connection to make the between server and client secure and effective.
Here is solution for you to redirect http to https (ssl) by two ways one by using PHP and one by using .htaccess.
SSl (secure socket layer) or https version of a website makes it more secure and reliable for users to use.
But one of the main problems for new web designers after installing SSL in their server is that even after installing ssl in their server when users type xyz.com in their browser the same http version of website is shown to user.
Below are given two solutions to the problem for you; one by using PHP and another by using HTACCESS.
1> Redirect http to https using PHP:
You can simply add the following function in your website and call it when ever you need to redirect to http request to your site to https.
function redirectToHTTPS()
{
if($_SERVER['HTTPS']!=="on")
{
$redirect= "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
header("Location:$redirect");
}
}
2> Redirect http to https using .htaccess.
You can simply add the following code in the .htaccess file of the root directory of your website and all the user request with http will be redirect to https of your site.
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Popular Searches:
- htaccess redirect http to https
- redirect http to https htaccess
- htaccess redirect to https
- php redirect http to https
- redirect to https htaccess
- redirect http to https php
- htaccess redirect https
- php redirect to https
- htaccess http to https
- htaccess redirect http https
- http to https redirect htaccess
- htaccess redirect https to http
- redirect https to http htaccess
- redirect http to https in php
- htaccess https redirect
- htaccess redirect from http to https
- php http to https redirect
- redirect http to https using htaccess
- php redirect from http to https
- http to https redirect php
- php redirect http https
- htaccess http to https redirect
- https htaccess
- How to redirect http to https in php
- redirect https to http php
- php redirect https to http
- http to https htaccess
- php redirect to ssl
- how to redirect http to https
- PHP http https

2 Comments
main problems for new web designers after installing SSL in their server is that even after installing ssl in their server when users type xyz.com in their browser the same http version of website is shown to user.
Nice post here