Skip to content

Instantly share code, notes, and snippets.

@jiceb
Created April 24, 2012 07:18
Show Gist options
  • Save jiceb/2477402 to your computer and use it in GitHub Desktop.
Save jiceb/2477402 to your computer and use it in GitHub Desktop.
Remove trailing slash with .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# where the magic is done !
RewriteRule (.*)/$ $1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
@stefenzzz
Copy link

how about adding trailing slash in the end if there is no trailing slash

@JTorresConsulta
Copy link

JTorresConsulta commented Jun 23, 2023

how about adding trailing slash in the end if there is no trailing slash

RewriteRule (.*[^/])$ $1/ [L]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment