简体   繁体   English

在URL的Laravel中强制http到https重定向(不带“ www”)

[英]Force http to https redirect in Laravel (without “www”) in URL

I am beginner in Laravel. 我是Laravel的初学者。 I use in my project Laravel 5.8. 我在我的项目Laravel 5.8中使用。 This is my htacess: 这是我的努力:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    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} (.+)/$
    RewriteRule ^ %1 [L,R=301]

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

How can I make redirect from http://name.com , http://www.name.com , https://www.name.com to https://name.com ? 我怎样才能使从重定向http://name.comhttp://www.name.comhttps://www.name.comhttps://name.com

It's posible in htacess or Middleware? 在htacess或中间件中可以吗?

You can use this in your .htaccess 您可以在.htaccess中使用它

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

这是用于强制将HTTP重定向到https的.htaccess片段

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / Options +SymLinksIfOwnerMatch ​ RewriteCond %{HTTPS} =on RewriteRule ^ - [env=proto:https] ​ RewriteCond %{HTTPS} !=on RewriteRule ^ - [env=proto:http] ​ RewriteCond %{REQUEST_URI} "!(^|/)\\.well-known/([^./]+./?)+$" [NC] RewriteCond %{SCRIPT_FILENAME} -d [OR] RewriteCond %{SCRIPT_FILENAME} -f RewriteRule "(^|/)\\." - [F] ​ RewriteCond %{HTTP_HOST} ^domainname\\.com$ [NC] RewriteRule ^(.*)$ http://domainname.com$1 [R=301,L] ​ RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) https://domainname.com/$1 [R,L] ​ ​ ​ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] ​ </IfModule>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM