http到https apacheredirect

环境与Apache的Centos

尝试设置从http到https的自动redirect

From manage.mydomain.com --- To ---> https://manage.mydomain.com 

我已经尝试将以下内容添加到我的httpd.conf,但它不起作用

  RewriteEngine on ReWriteCond %{SERVER_PORT} !^443$ RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L] 

有任何想法吗?

我实际上已经遵循这个例子,它为我工作:)

 NameVirtualHost *:80 <VirtualHost *:80> ServerName mysite.example.com DocumentRoot /usr/local/apache2/htdocs Redirect permanent / https://mysite.example.com/ </VirtualHost> <VirtualHost _default_:443> ServerName mysite.example.com DocumentRoot /usr/local/apache2/htdocs SSLEngine On # etc... </VirtualHost> 

然后做:

/etc/init.d/httpd restart

 RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} 

http://www.sslshopper.com/apache-redirect-http-to-https.html

要么

http://www.cyberciti.biz/tips/howto-apache-force-https-secure-connections.html

searchapache redirect http to https和降落在这里。 这是我在Ubuntu上做的:

1)启用模块

 sudo a2enmod rewrite sudo a2enmod ssl 

2)编辑您的网站configuration

编辑文件

 /etc/apache2/sites-available/000-default.conf 

内容应该是:

 <VirtualHost *:80> RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} </VirtualHost> <VirtualHost *:443> SSLEngine on SSLCertificateFile <path to your crt file> SSLCertificateKeyFile <path to your private key file> # Rest of your site config # ... </VirtualHost> 
  • 请注意,SSL模块需要证书。 您将需要指定现有的证书 (如果您购买了一个证书 )或自行生成自签名证书 。

3)重新启动apache2

 sudo service apache2 restart 

其实,你的话题属于https://serverfault.com/,但你仍然可以尝试检查这些;.htaccess指令:

 RewriteEngine on RewriteCond %{HTTPS} off RewriteRule ^(.*) https://%{HTTP_HOST}/$1 

这个代码适合我。

 # ----------port 80---------- RewriteEngine on # redirect http non-www to https www RewriteCond %{HTTPS} off RewriteCond %{SERVER_NAME} =example.com RewriteRule ^ https://www.%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent] # redirect http www to https www RewriteCond %{HTTPS} off RewriteCond %{SERVER_NAME} =www.example.com RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent] 
 # ----------port 443---------- RewriteEngine on # redirect https non-www to https www RewriteCond %{SERVER_NAME} !^www\.(.*)$ [NC] RewriteRule ^ https://www.%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent] 

这对我工作:

 RewriteCond %{HTTPS} =off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [QSA,L,R=301]