开发者

Redirect http to https

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

Now i make the folder 'test' secure

So the site is aviala开发者_如何学JAVAble 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?


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


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>


<!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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜