I am trying to redirect all my http requests to https in Laravel 5. Is there any documentation in Laravel 5 for this action. Else, Help me with code how to do that. Thanks in advance.
-
you need to redirect back or redirect any particular page or what ????? – Hamelraj Feb 04 '16 at 07:03
-
You need to make changes in your `.htaccess` file if you're using a APACHE serve. Read more here http://www.easylaravelbook.com/blog/2015/05/27/redirecting-to-https-in-laravel-5/ – Bharat Geleda Feb 04 '16 at 07:06
-
Use middleware: http://stackoverflow.com/questions/28402726/laravel-5-redirect-to-https – jardis Feb 04 '16 at 07:08
-
I need to redirect all pages to https if he request http – karthick Feb 04 '16 at 07:08
-
Check my update answer – Ravi Hirani Feb 04 '16 at 11:03
2 Answers
You can do redirection from http to https with htaccess file. Put below code in your .htaccess
file.
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.
To understand how rules are working check this link.
In many cases, you can also just add those lines to a file named .htaccess in the folder that you want to redirect http to https.
Now, when a visitor types http://www.yoursite.com/mypage.htm the server will automatically redirect http to https so that they go to https://www.yoursite.com/mypage.htm
Note: You can also redirect a single page from http to http in Apache by using this in your configuration file or .htaccess file:
RewriteEngine On
RewriteRule ^apache-redirect-http-to-https\.html$ https://www.yoursite.com/apache-redirect-http-to-https.html [R=301,L]
This link will also help you.
Hope it will help you :)

- 1
- 1

- 6,511
- 1
- 27
- 42
-
I need to redirect pages from http to https. Say, I have http://example.com/user, I need to redirect that to https://example.com/user. I tried with the above code in laravel 5, its redirecting to index.php – karthick Feb 04 '16 at 09:34
hey to redirect any pages you have to use in your controller on top
use Redirect;
in your function you can call which you want like this
return Redirect::route('foldername.filename') //ex - return Redirect::route('consignees.show')
and redirect back you can use this
return redirect()->back();
check this link

- 4,676
- 4
- 19
- 42