1

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?

Linto
  • 1,234
  • 3
  • 25
  • 41
  • 1
    Looks like a duplicate of this question: http://stackoverflow.com/questions/4083221/how-to-redirect-all-http-requests-to-https – rojoca Feb 24 '11 at 19:41

3 Answers3

4

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
Chris Baker
  • 49,926
  • 12
  • 96
  • 115
  • Chris, why do you need the or `!$_SERVER['HTTPS']`? if it's already https why do you need to redirect it to https? – The Muffin Man Feb 24 '11 at 19:49
  • If you're already on HTTPS, then the superglobal `$_SERVER['HTTPS']` will be set. If that variable is **not** set, then you are not on HTTPS, so you redirect. Thus, `if (!isset($_SERVER['HTTPS']))` - in English, "If $_SERVER['HTTPS'] is NOT set..." – Chris Baker Feb 24 '11 at 19:57
1

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>
Loyl
  • 11
  • 1
0
<!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.

Natkeeran
  • 1,719
  • 6
  • 29
  • 52