【问题标题】:Redirecting to https on .htaccess with single page application使用单页应用程序重定向到 .htaccess 上的 https
【发布时间】:2021-08-21 17:18:28
【问题描述】:

htaccess 用于单页应用程序,我想添加 https 重定向。

<ifModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.php [QSA,L]
</ifModule>

我尝试应用它,但网络服务器无限期重定向

<ifModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.php [QSA,L]

    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
</ifModule>

【问题讨论】:

    标签: .htaccess apache2


    【解决方案1】:

    以下列方式保存您的 htaccess 规则文件。请确保在测试您的 URL 之前清除您的浏览器缓存。

    <ifModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
    
        RewriteCond %{HTTPS} off
        RewriteRule ^(.*)/?$ https://example.com/$1 [L,NE,R=301]
    
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)/?$ index.php [QSA,L]
    
    </ifModule>
    

    OP 尝试中的修复: 首先更改重写规则的正则表达式以匹配可选的 / in 规则(两个规则)。然后将所需的标志 NE 应用于第一个重写规则。也改变了规则的顺序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多