在 Laravel 5.8 中的 htaccess 中重定向

我是 Laravel 的初学者。我在 Laravel 5.8 中制作我的项目。我在域中有网站:https : //myname.com

我需要带有选项的 .htacess: - 从 http 重定向到 https, - 从 www.myname.com 重定向到 myname.com

我怎样才能做到这一点?


湖上湖
浏览 159回答 1
1回答

慕的地6264312

您必须拥有 SSL 证书才能使用 https。这是我的 .htaccess 文件,它适用于我从 http 重定向到 https。<IfModule mod_rewrite.c>&nbsp; &nbsp; <IfModule mod_negotiation.c>&nbsp; &nbsp; &nbsp; &nbsp; Options -MultiViews -Indexes&nbsp; &nbsp; </IfModule>&nbsp; &nbsp; RewriteEngine On&nbsp; &nbsp; # Handle Authorization Header&nbsp; &nbsp; RewriteCond %{HTTP:Authorization} .&nbsp; &nbsp; RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]&nbsp; &nbsp; # Redirect Trailing Slashes If Not A Folder...&nbsp; &nbsp; RewriteCond %{REQUEST_FILENAME} !-d&nbsp; &nbsp; RewriteCond %{REQUEST_URI} (.+)/$&nbsp; &nbsp; RewriteRule ^ %1 [L,R=301]&nbsp; &nbsp; # Handle Front Controller...&nbsp; &nbsp; RewriteCond %{REQUEST_FILENAME} !-d&nbsp; &nbsp; RewriteCond %{REQUEST_FILENAME} !-f&nbsp; &nbsp; RewriteRule ^ index.php [L]&nbsp; &nbsp; RewriteEngine On&nbsp;&nbsp; &nbsp; RewriteCond %{SERVER_PORT} 80&nbsp;&nbsp; &nbsp; RewriteRule ^(.*)$ https://www.sitename.com/$1 [R,L]</IfModule><IfModule mod_headers.c>&nbsp; &nbsp; <FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css|css)$">&nbsp; &nbsp; &nbsp; &nbsp; Header set Access-Control-Allow-Origin "*"&nbsp; &nbsp; </FilesMatch></IfModule>
打开App,查看更多内容
随时随地看视频慕课网APP