1

I need to rewrite http://example.com:8/?123&x=abc to http://example.com:8/lorem/ipsus/123/abc without any redirection.

I've already done this rule :

RewriteCond %{SERVER_PORT} ^8$
RewriteCond %{QUERY_STRING} ^(\d+)&x=(.+)$
RewriteRule ^/?$ lorem/ipsus/%1/%2 [QSD,P]

But Laravel handle the wrong route (/). So I've tried to change routes but it seems that Laravel can't handle query string routes :

Route::get('?{key}&x={value}', 'myController@store');
Route::get('{data}', 'myController@store')->where(
[
    'data' => '\?\d+&x=.+'
]);
Route::get('lorem/ipsus/{key}/{value}', 'myController@store');

None of them actually work.

This is the laravel .htaccess :

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

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

And I'm lost... Any help would be appreciated :)

SpiderWan
  • 948
  • 10
  • 10
  • Remove the htaccess rewrite rules of your first code. Laravel only works with the redirection to index.php, else it would never reach the index.php. – Jan Willem Sep 05 '16 at 07:09
  • But the rule in my first code is the rule I want to work with Laravel. On the virtual host, it's working - and not on the htacces... strange... – SpiderWan Sep 06 '16 at 12:03

1 Answers1

0

I've managed to do it by adding my custom rule on the virtual host, not the htaccess, with apache mod proxy (P flag):

<VirtualHost *:8>

        [...]

        RewriteEngine On
        RewriteCond %{SERVER_PORT} ^8$
        RewriteCond %{QUERY_STRING} ^(\d+)&x=(.+)$
        RewriteRule ^/?$ lorem/ipsus/%1/%2 [QSD,P]

        <Directory "/var/www">
                AllowOverride All
        </Directory>

</VirtualHost>
SpiderWan
  • 948
  • 10
  • 10