开发者

Redirect http to https

开发者 https://www.devze.com 2023-02-13 11:51 出处:网络
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

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

精彩评论

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