I'm using Laravel 5 and notice that the pagination is adding a trailing slash before the ?page=#
and with that, it always redirect to a 301 page.
http://example.com/news/articles/?page=2
will do a 301 redirect to http://example.com/news/articles?page=2
This is causing my pagination using ajax to slow down because it is having 2 responses.
How to make laravel accept http://example.com/news/articles/?page=2
so it won't make a 301 redirect?
I base it through this site which is using LengthAwarePaginator
.
If you look in your app/public/.htaccess
file you will see this line:
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
By removing it you will disable trailing slash redirect.
I'd do this in my controller instead of modifying .htaccess
$posts= Article::latest()->paginate(4);
$posts->setPath('');//just add this line after your paginate function
or some users might prefer to add this line when they generate links in view
$links = str_replace('/?', '?', $posts->render());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With