Trying to redirect with and without trailing slash
Solution 1:
Please use bellow syntax
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !example.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://example.com/$1/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
makes shure that files that are existing will not get a slash added.
RewriteCond %{REQUEST_URI} !example.php
exludes a sample url that shouldn’t be rewritten.
RewriteCond %{REQUEST_URI} !(.*)/$ finally fires when a urls doesn’t contain a trailing slash – this is all what we want. Now we need to redirect these url with the trailing slash:
RewriteRule ^(.*)$ http://example.com/$1/ [L,R=301]
does the 301 redirect to the url with the trailing slash appended for us. You should replace domain.com with your url.