Laravel 5 pagination with trailing forward slash at 301

I am using Laravel 5 and notice that pagination adds a trailing slash in front of ?page=#

it and with that it always redirects to the 301 page.

http://example.com/news/articles/?page=2

will make 301 redirects to http://example.com/news/articles?page=2

This is causing my ajax pagination to slow down because it has 2 responses.

How do I force laravel to accept http://example.com/news/articles/?page=2

so that it doesn't redirect 301?

I am basing it on this site that uses LengthAwarePaginator

.

+3


source to share


3 answers


If you look in your file app/public/.htaccess

you will see this line:

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

      



By removing it, you turn off the trailing slash relay.

+4


source


I would do this in my controller instead of changing .htaccess

    $posts= Article::latest()->paginate(4);
    $posts->setPath('');//just add this line after your paginate function

      



or some users may prefer to add this line when they generate links in sight

$links = str_replace('/?', '?', $posts->render());

      

+1


source


Answer to

@shaddys is the most correct solution, but I couldn't use it because of the other routes. So I just did this,

$.ajax({
     url: url.replace('/?','?'),
      ....
});

      

With this, you get a working pagination and no redirects.

0


source







All Articles