Get rid of trailing slash off URL requests with .htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]

Yeah, that’s it. So:

  1. /path/dir/ is redirected to /path/dir
  2. /path/dir/?a=1&b=2 is redirected to /path/dir?a=1&b=2
Scroll to Top