重定向到https:// www。当没有子域,只有https:当有

问题描述:

当有人进入http://(不安全),有两种可能的情况。我想编程一个.htaccess文件来解决以下两种方法:重定向到https:// www。当没有子域,只有https:当有

1)他们不使用子域。

解决方案:重定向到https://www. +剩余的URL。

2)他们使用两种http://www.http://subdomain.

解决方案:重新定向到https://subdomain OR https://www.(取使用)+剩余的URL。

如何在我的.htaccess文件中解决这个问题?

这里是我当前的文件:

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|css|js|font|uploads|robots\.txt) 
RewriteRule ^(.*)$ /index.php/$1 [L] 

启用mod_rewrite的,并通过httpd.conf的.htaccess,然后把这个代码在你.htaccessDOCUMENT_ROOT目录:

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

# redirect to https://www. + remaining URL. 
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC] 
RewriteRule^https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

# They use either http://www. or http://subdomain. 
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^[^.]+\.domain\.com$ [NC] 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 
+0

就像一个魅力!谢谢! – 2013-03-23 21:30:06

+0

不客气,很高兴它解决了。 – anubhava 2013-03-24 09:02:55