By default, WordPress often adds a trailing slash (/) to URLs based on your permalink settings.
For example:
- With trailing slash:
https://example.com/sample-page/ - Without trailing slash:
https://example.com/sample-page
If you want to remove trailing slashes from your WordPress URLs, follow the steps below.
Table of Contents
Before You Start
Changing your URL structure can affect:
- Search engine rankings
- Existing backlinks
- Cached pages
- Internal links
Before making any changes:
- Create a full website backup
- Export your SEO data if necessary
- Clear all caches after implementation
Check Your Permalink Structure
- Log in to your WordPress dashboard.
- Navigate to Settings → Permalinks.
- Review your current permalink structure.
If your structure ends with a slash, WordPress will automatically generate URLs with trailing slashes.
Example:
/%postname%/
To remove the trailing slash, change it to:
/%postname%
- Click Save Changes.
WordPress will automatically update its rewrite rules.
Add a Redirect Rule
To avoid duplicate content and preserve SEO value, redirect old URLs with trailing slashes to the new version.
If your website uses Apache, add the following rule to your .htaccess file above the WordPress section:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=301,L]
If you use NGINX, add the following rule to your server configuration:
rewrite ^/(.+)/$ /$1 permanent;
After making changes, reload your web server configuration.
Clear Your Cache
If you use a caching plugin or CDN service, clear all caches after updating your URL structure.
This includes:
- WordPress cache plugins
- Server-side caching
- Browser cache
- CDN cache
Avoid Editing functions.php
Although you may find code snippets that remove trailing slashes using WordPress filters, modifying permalink behavior in the functions.php file is not recommended.
Incorrect filters can cause:
- Redirect loops
- Broken canonical URLs
- Plugin compatibility issues
- SEO problems
If custom URL handling is required, implement it in a child theme or use server-level redirects instead.
Test Your Changes
After removing trailing slashes:
- Open several pages manually
- Verify that old URLs redirect correctly
- Check for 404 errors
- Test canonical tags
- Inspect your website in Google Search Console
You can also use online redirect checkers to confirm that redirects return a 301 Moved Permanently status.
Summary
The safest way to remove trailing slashes in WordPress is to adjust your permalink structure and configure proper server-side redirects.
Avoid modifying URL behavior directly in the functions.php file unless you fully understand the impact on WordPress routing and SEO.
Always back up your website before changing permalink settings.