phpapache.htaccesslaravelmod-rewrite

$_GET is always empty using .htaccess RewriteRule with L flag


My laravel application is working well on localhost, but now having moved my application to a production server, it is no longer recognizing any $_GET variables passed through the URL. My production server is set up to allow multiple laravel installations, and I am handling the rewriting with a vhost.conf file and an .htaccess file located in the laravel root.

.htaccess

<IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteBase /
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteRule ^(.*)$ /international-experts/index.php/?$1 [L]
</IfModule>

vhost.conf

Alias /international-experts "/srv/http/international-experts/public"
<Directory /srv/http/international-experts>
  Options Indexes Includes FollowSymLinks MultiViews
  AllowOverride AuthConfig FileInfo Indexes
  Order allow,deny
  Allow from all
</Directory>

What I have done to test it is with print_r($_GET) on multiple pages. Nothing. Reading up on the problem, it sounds like MultiViews might be part of the problem. I know I'm not the only one handling multiple laravel installations on the same server... has anyone else had to tackle this problem?


Solution

  • In the rewrite rule

    RewriteRule ^(.*)$ /international-experts/index.php/?$1 [L]
    

    you create a new query string with ?$1 and the default behaviour in this case is to throw away the old query string. You need to use the flag QSA, which you can remember as "query string append"

    RewriteRule ^(.*)$ /international-experts/index.php/?$1 [L,QSA]
    

    If not enough to solve your problem, it is surely a part of it.