2017-02-09 145 views
-1

我需要的,如果一個顧客進入以下網址於瀏覽器上https://domain.com如何網站重定向到https://開頭不是重定向到https:// WWW

重定向。

  1. domain.com
  2. www.domain.com
  3. http://domain.com
  4. http://www.domain.com

我使用笨框架。 請分享我,如何通過更改.htaccess來管理它。

我使用下面的代碼在.htaccess

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] 
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 

    RewriteBase /demo 

    RewriteCond %{REQUEST_URI} ^system.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 

    RewriteCond %{REQUEST_URI} ^application.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 

    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?/$1 [L] 
+2

分享你的.htaccess – Naincy

+1

你可以用你的.htaccess做。 –

+5

[htaccess重定向到https:// www]可能的重複(http://stackoverflow.com/questions/13977851/htaccess-redirect-to-https-www) – drmonkeyninja

回答

0

您可以使用:

RewriteCond %{HTTP_HOST} ^www\.(.+) [NC] 
RewriteRule^https://%1%{REQUEST_URI} [NE,L,R=301] 
RewriteCond %{HTTPS} off 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301] 
+0

感謝它的工作,請讓我知道我是否需要添加下面的腳本也沒有? RewriteRule ^(。*)$ /index.php RewriteRule ^(。*)$ /index.php?/$1 [L] RewriteCond%{REQUEST_URI}^application。* RewriteRule ^(。*)$ /index.php ?/ $ 1 [L] 的RewriteCond%{} REQUEST_FILENAME!-f 的RewriteCond%{} REQUEST_FILENAME!-d 重寫規則^(。*)$的index.php?/ $ 1 [L] – Manraj

+0

它涉及到如何您的網站作品,而不是服務器。但我認爲是。將它們添加到其他之後。 – Croises

+1

由於這個答案解決了您的問題,[您應該在答案的左上角點擊**勾號**標記答案已被接受](http://meta.stackexchange.com/a/5235/160242)謝謝 ! – Croises