Redirection to Enforce/Remove Trailing Slash on URLs
This article contains guidance on how to enforce or remove trailing slash on your URLs.
Note: As long as your canonical URLs are correctly set, Google will index the desired URL even without these fixes.
Add a trailing slash for Apache/LiteSpeed
This applies only in sites where WP Rocket's redirect rules are present in the htaccess file.
If you need to enforce a trailing slash at the end of your URLs you can use the following helper plugin
📥 Download (.zip): WP Rocket | Enforce Trailing Slash on URLs
Developers: You can find the code for this plugin on GitHub.
Add Trailing Slash for WordPress Multisite
If you need to enforce a trailing slash at the end of your URLs you can use the following helper plugin
📥 Download (.zip): WP Rocket | Enforce Trailing Slash on multisite
Developers: You can find the code for this plugin on GitHub.
Remove a trailing slash for Apache/LiteSpeed
If you need to remove a trailing slash from the end of your URLs, you can use the following helper plugin.
📥 Download (.zip): WP Rocket | Remove Trailing Slash from URLs
Developers: You can find the code for this plugin on GitHub
Trailing slashes on NGINX servers
Configuring NGINX is more complicated since WP Rocket does not have access to the configuration of a NGINX server; NGINX servers don't use .htaccess files, so, this type of server must be configured by a Sysadmin.
If you have access to the NGINX server configuration, you can use the next rules:
Force Trailing Slash
# Force Trailing Slash (less REST API calls and files) if ($request_uri !~ "^/wp-json") { rewrite ^([^.]*[^/])$ $1/ permanent; }
Remove Trailing Slash
# Remove Trailing Slash (less REST API calls and files) if ($request_uri !~ "^/wp-json") { rewrite ^/(.*)/$ /$1 permanent; }