Ad

Laravel Return 302 In Some Machine - Browser

- 1 answer

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}','[email protected]');
});

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

Ad

Answer

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]
Ad
source: stackoverflow.com
Ad