Linto
Linto

Reputation: 1282

Redirect http to https

I had a site http://www.test.com

Now i make the folder 'test' secure

So the site is avialable in https://www.test.com

My requirement is ,when some one type http://www.test.com ,

then it should go to https://www.test.com.

Is there any way using .Htaccess or any other method?

Upvotes: 1

Views: 1022

Answers (3)

Loyl
Loyl

Reputation: 11

In Apache2 configuration, you could use the redirect command :

<VirtualHost *:80>
    ServerName www.test.com
    Redirect / https://www.test.com/
</VirtualHost>

<VirtualHost *:443>
    ServerName www.test.com
    ...
</VirtualHost>

Upvotes: 1

Chris Baker
Chris Baker

Reputation: 50612

Simple method within PHP:

if (!isset($_SERVER['HTTPS']) || !$_SERVER['HTTPS']) {
  header('location: https://mydoamin.com');
  die();
}

htaccess method:

SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "mydomain.com"
ErrorDocument 403 https://mydomain.com

Upvotes: 4

Natkeeran
Natkeeran

Reputation: 1749

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Your Page Title</title>
<meta http-equiv="REFRESH" content="0;url=http://www.the-domain-you-want-to-redirect-to.com"></HEAD>
<BODY>
Optional page text here.
</BODY>
</HTML>

That should do it.

Upvotes: 0

Related Questions