Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel return 302 in some machine - browser

I have a stranger behavior in my application, if open this url

http://example.com/Pd/Country/1

In some machines and browser, I got the expected result and response code is 200 where other machines return 302

In my routes

Route::group(array('prefix' => 'Pd'), function() {
   Route::get('Country/{id}','CountryController@getAll');
});

Updates I found out the problem is session not persisted in some machine and browser , I have got some suggestions to add Session::save(); after Session::push('keyvalue',$keyvalue );but still not working

like image 614
ikuchris Avatar asked Jan 18 '16 14:01

ikuchris


1 Answers

The Real Problem

The url were different i.e: Sessions set on example.com and the next request done on http://www.example.com/on which the sessions were not set .

The Solution

I had to change my .htaccess file so that whether user type www.example.com , example.com or http://example.com/ will be changed to http://www.example.com/

Options -MultiViews
RewriteEngine On

# remove index.php
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^ http://www.example.com%{REQUEST_URI} [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
like image 173
ikuchris Avatar answered Oct 24 '22 07:10

ikuchris