URL is appending forward slash '/' before query string

Question

I'm facing a strange issue , when I try to hit url like

www.mywebsite.com/walkthrough?hostid=12345

It is automatically appending '/' before'?' in the url. like

www.mywebsite.com/walkthrough/?hostid=12345

and hence I'm not able to get parameter hostid.

routes

 Route::get('/walkthrough', ['uses' => 'WalkthroughController@index']);   

HTACCESS

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>
Options -Indexes
RewriteEngine On
# 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] 
#php_value allow_url_fopen 0
#php_value allow_url_include 0
</IfModule>

why this is happening ? Any help is much much appreciated..Thanks.


Show source
| url   | laravel   | php   | routes   | laravel-5   2017-01-07 10:01 2 Answers

Answers ( 2 )

  1. 2017-01-07 11:01

    This is most likely a .htaccess issue. Though I am surprised you can't still pluck out the url parameter, as it should make little difference if the / is there or not.

    A typical laravel htaccess file should look like this:

    <IfModule mod_rewrite.c>
        <IfModule mod_negotiation.c>
            Options -MultiViews
        </IfModule>
    
        RewriteEngine On
    
        # 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]
    
        # Handle Authorization Header
        RewriteCond %{HTTP:Authorization} .
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    </IfModule>
    

    EDIT

    Based on a discussion in the comments, it seems that a conflicting directory in the public directory called walkthrough was/is causing the trouble.

    Laravel will only trim off the trailing / if there isn't a matching directory (rightly so).

    There is no harm having the trailing / though.

  2. 2017-01-07 11:01

    Try defining the route like this as mentioned in laravel documentation.

    Route::get('walkthrough', 'WalkthroughController@index'); 
    

    Refer basic routing

◀ Go back