Redirection to enforce/remove trailing slash on URLs
WP Rocket will respect the trailing slash configuration you have for your site. However, this feature won't work in the following cases:
- WP Rocket rewrite rules are present in the .htaccess file.
This is, when the mobile-specific cache (or the Mobile Cache) or WebP Compatibility features are disabled. Also, when plugins whose compatibility with WP Rocket includes mandatory and dynamic cookies, such as Cookie Notice, are not installed. - NGINX rewrite rules are present (including https://github.com/SatelliteWP/rocket-nginx)
- Server cache is used
This article contains guidance on how to enforce or remove trailing slash on your URLs, needed on the above cases.
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; }