2013-03-22 87 views
1

當有人進入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] 

回答

1

啓用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

相關問題