2016-02-04 273 views
1

我正在尝试将所有http请求重定向到Laravel 5中的https。Laravel 5中是否存在此操作的任何文档。否则,帮我用代码如何做到这一点。提前致谢。在Laravel 5中将所有Http请求重定向到https https

+0

你需要回到重定向或重定向任何特定网页或什么????? – Hamelraj

+0

如果您使用的是APACHE服务器,则需要在您的'.htaccess'文件中进行更改。阅读更多在这里http://www.easylaravelbook.com/blog/2015/05/27/redirecting-to-https-in-laravel-5/ –

+0

使用中间件:http://stackoverflow.com/questions/28402726/laravel -5-重定向到HTTPS – jardis

回答

2

您可以使用htaccess文件从http重定向到https。将以下代码放入您的.htaccess文件中。

RewriteEngine On 
RewriteCond %{HTTPS} !=on 
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L] 

OR

Options +FollowSymLinks 
RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

OR

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L] 
// change example.com with your website domain 
// This will redirect all requests received on port 80 to HTTPS. 

要了解规则正在检查这个link

在很多情况下,您还可以将这些行添加到要将http重定向到https的文件夹中名为.htaccess的文件中。

现在,当访客类型http://www.yoursite.com/mypage.htm让他们去https://www.yoursite.com/mypage.htm

注意,服务器会自动重定向HTTP到https:您还可以从HTTP通过使用这种重定向一个页面中的Apache到http您的配置文件或.htaccess文件:

RewriteEngine On 
RewriteRule ^apache-redirect-http-to-https\.html$ https://www.yoursite.com/apache-redirect-http-to-https.html [R=301,L] 

link也将帮助你。

希望它会帮助你:)

+0

我需要从HTTP网页重定向到HTTPS。说,我有http://example.com/user,我需要将其重定向到https://example.com/user。我尝试了laravel 5中的上述代码,将其重定向到index.php – karthick

+0

检查我的OR条件是否已更新 –

1

哎重定向要这样

你有你的控制器在功能使用上的顶部

use Redirect; 

任何页面,你可以调用

return Redirect::route('foldername.filename') //ex - return Redirect::route('consignees.show') 

和重定向回你可以使用这个

return redirect()->back(); 

检查link

-1

我已将URL::forceSchema("https");加到我的路线文件上,它工作正常! 它改变了链接为https在Laravel 5.2

相关问题