Remove trailing slashes

后端 未结 4 1716
清歌不尽
清歌不尽 2021-01-19 00:11

I\'d like to work with pages without trailing slashes. So now I want my URL\'s with an trailing slash to redirect (using .htaccess) to the same URL without the trailing slas

4条回答
  •  醉梦人生
    2021-01-19 00:37

    Wordpress redirects depending on what your permalink structure is. So any changes to .htaccess helps little since Wordpress will add/remove them for you and peform a wp_redirect() after .htaccess done things. In worst case you end up with a redirect loop.

    A solution is to turn off Wordpress redirecting using.

    // perhaps an if(is_something()) before here ...
    add_filter('redirect_canonical', '__return_false');
    

    You should wrap this inside an if statement or such where you perform a check for a certain page/directory/etc. Putting the above directly in your functions file will turn off wordpress redirections and probably break things.

提交回复
热议问题