Remove trailing slash from non-filepath URLs

A trailing slash is the forward slash placed at the end of a URL. The trailing slash is generally used to mark a directory, and if a URL is not terminated using a trailing slash, this generally points to a file. A trailing slash should not be added for URLs that end in a file name, such as .html, .php, .aspx, .txt, .pdf or .jpg.

Should you keep or remove the trailing slash on URLs?

The short answer is that the trailing slash does not matter for your root domain or subdomain. Google sees the two as equivalent. But trailing slashes do matter for everything else because Google sees the two versions (one with a trailing slash and one without) as being different URLs.

# Turn on Rewrite Engine
RewriteEngine On

# Remove trailing slash from non-filepath urls
RewriteCond %{REQUEST_URI} /(.+)/$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ https://domain.com/%1 [R=301,L]

I do not use cookies on this website

🍪🍪 What cookies?


Your privacy is important. That's why this website doesn't track visitors with fingerprinting, your IP address or cookies.


Web analytics data is your own. Reclaim it.

Gain back control with a privacy-focused web analytics platform (using a cookie-less architecture) from: Data Centurion.