2016-02-04 170 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

相關問題