htaccess 多个规则和 http 到 https

htaccess multiple rules and http to https

我正在尝试找出重写规则。我们目前有以下规则:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(blog\.)?example\.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/(public|scripts)/ [NC]
    RewriteRule ^(.*)$ /public/ [L]
</IfModule>

并且我们需要一个额外的规则来将所有 HTTP 流量重定向到 HTTPS。

我已经尝试了以下方法,但行不通。

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTPS} !on
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

    RewriteCond %{HTTP_HOST} ^(blog\.)?example\.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/(public|scripts)/ [NC]
    RewriteRule ^(.*)$ /public/ [L]
</IfModule>

尝试向您的重定向规则添加 L 标志:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTPS} !on
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R]

    RewriteCond %{HTTP_HOST} ^(blog\.)?example\.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/(public|scripts)/ [NC]
    RewriteRule ^(.*)$ /public/ [L]
</IfModule>