2017-02-09 138 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