0
votes

I have installed WordPress multisite in sub-directory abc.com/en/. I want to remove the trailing slash for SEO purposes. So pages like abc.com/en/xxx/ will be 301 redirected to abc.com/en/xxx without a trailing slash.

After checking many resources (I am using Nginx), I found the code below to be working for all pages except the multisite homepage abc.com/en/. WordPress always 301 redirects abc.com/en to abc.com/en/ with a trailing slash, so it will cause a redirect loop.

if (!-d $request_filename) {
   rewrite ^/(.*)/$ /$1 permanent; 
}

So how can I remove the trailing slash for the en/ too? Many thanks in advance!

1

1 Answers

0
votes

add this line to functions.php

This this line you can fix redirect from domain.com/page to domain.com/page/ with trail slash

remove_filter('template_redirect', 'redirect_canonical');

Please don't forget clear cache or test on clean browser