使用htaccess将网站http重定向到lapsvel中的https

问题描述 投票:0回答:2

我有一个Laravel项目。我用Godaddy。最近,我在我的网站上安装了SSL证书,所以当我在浏览器中键入https://example.com时它可以工作,但是当我写example.com时,它通过HTTP连接。

为了解决这个问题,我将这些行添加到我的根文件夹.htaccess文件中:

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

但这重定向给我https://example.com/public

我添加了两个htaccess,一个在根文件夹中,第二个在公共文件夹中。

第一个htaccess代码:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L,NC]

第二个htaccess代码是:

选项-MultiViews -Indexes

RewriteEngine On

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^ %1 [L,R=301]


# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

我怎样才能实现这个https://example.com

提前致谢!

php laravel apache ssl
2个回答
0
投票
<IfModule mod_rewrite.c>
    RewriteEngine on
    Options +FollowSymlinks
    #redirect http non-www to https://www
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} ^(www\.)?your-domain\.com$
    RewriteRule (.*) https://www.your-domain.com/$1 [R=301,L]
    #redirect https non-www to www
    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP_HOST} ^your-domain\.com$
    RewriteRule (.*) https://www.your-domain.com/$1 [R=301,L]
</IfModule>

我正在使用它来重定向。


0
投票

试试这段代码:

RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^/(.*)$ http://%1/$1 [R]
RewriteRule ^/?$ "https\:\/\/example\.com\/" [R=301,L]
© www.soinside.com 2019 - 2024. All rights reserved.