www和https的htaccess重定向问题


htaccess redirection issue for www and https

我有domain-example.com。我使用的是Laravel 5。

我希望始终重定向到https://www.example.com/beta

现在,我的htaccess是:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
    RewriteEngine On
    RewriteBase /beta/
    RewriteCond %{HTTP_HOST} !^www'. [NC]
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301]
    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]
    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

现在,例如.com/beta,它重定向到https://example.com/beta

但当我们访问www.example.com/beta时,它会重定向到http://www.example.com/https://www.www.example.com/beta

请告知。

这样做:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
    RewriteEngine On
    RewriteBase /beta/
    RewriteCond %{HTTP_HOST} !^www'. [NC,OR]
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} ^(?:www'.)?(.+)$ [NC]
    RewriteRule ^(.*)$ https://www.%1%{REQUEST_URI} [L,R=301,NE]
    # Redirect Trailing Slashes...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301,NE]
    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

请确保在测试此更改之前清除浏览器缓存。