【问题标题】:How to redirect http to https://www.example.com using htaccess file?如何使用 htaccess 文件将 http 重定向到 https://www.example.com?
【发布时间】:2018-11-27 12:54:06
【问题描述】:
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

    RewriteCond %{HTTPS} off
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

我使用Codeigniter 框架创建了一个网站,我的域和主机位于GoDaddy。现在,我已经安装了SSL certificate 并使用我的网站进行管理。现在,当我在 URL 中使用example.com 时,它会将我重定向到https://www.example.com,但是当我点击我的login 页面时,它会显示Not Found 并且URL 看起来像https://www.example.com/index.php?/login,但我想要像https://www.example.com/login 这样的URL。那么,我该怎么做呢?请帮忙。

谢谢

【问题讨论】:

    标签: .htaccess codeigniter ssl-certificate


    【解决方案1】:
    1. 更改规则的顺序
    2. 有一个规则来重定向wwwhttp -&gt; https

    你的 .htaccess 应该是这样的:

    RewriteEngine on
    
    # redirect for adding www and https
    RewriteCond %{HTTPS} !on [OR]
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
    
    # front controller
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
    

    确保使用新的浏览器进行测试。

    【讨论】:

      【解决方案2】:

      请使用此 htaccess 规则将 100% 工作

      RewriteEngine on
      RewriteCond $1 !^(index\.php|resources|robots\.txt)
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 
      
      RewriteCond %{HTTPS} off
      RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
      RewriteCond %{HTTP_HOST} !^www\. [NC]
      RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
      

      【讨论】:

        【解决方案3】:

        使用这个:

        Options All -Indexes
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php/$1 [L]
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-06-18
          • 1970-01-01
          • 2020-12-21
          • 2014-03-04
          • 2019-06-25
          • 1970-01-01
          • 2011-07-06
          • 2011-08-12
          相关资源
          最近更新 更多