【问题标题】:How to redirect website to https:// not redirect to https://www如何将网站重定向到 https:// 而不是重定向到 https://www
【发布时间】:2017-02-09 12:10:39
【问题描述】:

我需要重定向https://domain.com

如果客户在浏览器上输入以下 URL。

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

我正在使用 Codeigniter 框架。 请分享我,如何通过更改 .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]

【问题讨论】:

标签: php .htaccess codeigniter


【解决方案1】:

你可以使用:

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]

【讨论】:

  • 谢谢它的工作,请让我知道我是否还需要添加以下脚本? 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]
  • 这与您网站的工作方式有关,与服务器无关。但我认为是的。在其他人之后添加它们。
猜你喜欢
  • 2016-09-24
  • 1970-01-01
  • 2021-04-02
  • 1970-01-01
  • 2012-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多