doujiang1913
doujiang1913
2017-06-27 07:35

Laravel 5.2 redirect() - > route()仅在生产时不起作用

Im facing this problem for the last 2 weeks (!!) Only on production env suddenly any redirect()->route() stopped working!

no matter what i do...it just wont work. my prod web is on https protocol, 3 weeks ago it was still working , then suddenly stopped.

here is my .htaccess file:

    # Enable Compression
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
</IfModule>
<IfModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>

# Leverage Browser Caching
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpg "access 1 year"
  ExpiresByType image/jpeg "access 1 year"
  ExpiresByType image/gif "access 1 year"
  ExpiresByType image/png "access 1 year"
  ExpiresByType text/css "access 1 month"
  ExpiresByType text/html "access 1 month"
  ExpiresByType application/pdf "access 1 month"
  ExpiresByType text/x-javascript "access 1 month"
  ExpiresByType application/x-shockwave-flash "access 1 month"
  ExpiresByType image/x-icon "access 1 year"
  ExpiresDefault "access 1 month"
</IfModule>
<IfModule mod_headers.c>
  <filesmatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf)$">
  Header set Cache-Control "max-age=2678400, public"
  </filesmatch>
  <filesmatch "\.(html|htm)$">
  Header set Cache-Control "max-age=7200, private, must-revalidate"
  </filesmatch>
  <filesmatch "\.(pdf)$">
  Header set Cache-Control "max-age=86400, public"
  </filesmatch>
  <filesmatch "\.(js)$">
  Header set Cache-Control "max-age=2678400, private"
  </filesmatch>
</IfModule>




<IfModule mod_headers.c>
# Set XSS Protection header
Header set X-XSS-Protection "1; mode=block"
</IfModule>

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 2 days"
ExpiresByType image/jpeg "access plus 2 days"
ExpiresByType image/gif "access plus 2 days"
ExpiresByType image/png "access plus 2 days"
ExpiresByType text/css "access plus 2 days"
ExpiresByType application/pdf "access plus 2 days"
ExpiresByType text/x-javascript "access plus 2 days"
ExpiresByType application/x-shockwave-flash "access plus 2 days"
ExpiresByType image/x-icon "access plus 2 days"
ExpiresByType text/html "access plus 2 days"
ExpiresDefault "access plus 2 days"
</IfModule>
## EXPIRES CACHING ##

## EXPIRES CACHING ##
<IfModule mod_headers.c>

Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Credentials "true"
Header set Access-Control-Allow-Methods "GET, PUT, POST, DELETE, OPTIONS"
#Header set Access-Control-Max-Age "1000"
Header always append X-Frame-Options "SAMEORIGIN"
# Header set Connection keep-alive



</IfModule>



<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
Options +FollowSymLinks

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]

 # Force SSL
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP:X-Forwarded-Proto} =http
  RewriteCond %{HTTP_HOST} ^testm.com

  RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]



    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

</IfModule>

here is my controller code that redirecting to the route:

.....

 return redirect()->route('admin.index.get')->withInput($request->only('admin', 'remember'));

.....

Here is my routes.php:

Route::group(['middleware' => ['auth','roles','custom-throttle','web'],'roles' => ['administrator'],'prefix' => 'admin', 'as' => 'admin.'], function() {

    Route::controller('/', 'AdminController', [

        //Basic
        'getIndex'                      => 'index.get'


    ]);


});

And i have AllowOverride All in httpd.conf, and Vhost.

What is wrong ? why its not working?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • douguwo2275 douguwo2275 4年前

    So, after lot of waisted time... i found the problem, hope it will help to anyone in the future.

    Im using AWS Elastic Beanstalk, I upload zip file with my project version to my Elastic Beanstalk environment and the EB unzip it and uploading to my EB instance/s, this way in case that i have more then 1 instance (server) to my app , i dont need to upload version to each one of then separately, all the instances connected to a Load balancer that redirecting the requests flow to my app.

    what happened is that in my env file configuration the session driver was "file" type, meaning its saving all the sessions locally in the storage folder in the project location (meaning on the server), the problem was when i was trying to log in, the session was created but then i was getting response from another instance (because the Load balancer) and of course there was no session there...

    so, for anyone that will ever face this specific problem, just change the session driver to memcached / redis / database

    点赞 评论 复制链接分享