Forum Moderators: phranque
### Enforce trailing slash
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://examplesite.com/$1/ [QSA,L,R=301] RewriteCond %{REQUEST_URI} !\.[a-z0-9]*$ [NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !\.[a-z0-9]*$ [NC] RewriteCond %{REQUEST_URI} !(.*)/$ ### Enforce trailing slash for urls missing one, except page numbers and .html
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.[a-z0-9]*$ [NC]
RewriteCond %{REQUEST_URI} !(.*)/\d*$
RewriteRule ^(.*)$ http://example.com/$1/ [QSA,L,R=301] RewriteRule ^([^.]+[^/.])$ http://example.com/$1/ [QSA,L,R=301] RewriteCond %{REQUEST_URI} !.*/\d*$
RewriteRule ^([^\.]+)$ http://example.com/$1/ [QSA,L,R=301] who in their right mind would put a period at the end of a URL? ;-)
Periods inside grouping brackets don't need to be escaped
Never put something in a condition that can go in the body of a rule (because it saves the server from having to evaluate conditions in the first place).
RewriteCond %{REQUEST_URI} !.*/\d+$
RewriteRule ^([^.]+[^/.])$ http://example.com/$1/ [QSA,L,R=301] RewriteCond %{REQUEST_URI} !.*/\d*$
RewriteRule ^([^.]+)$ http://example.com/$1/ [QSA,L,R=301] What's the difference?
the RewriteRule will not be evaluated for requests ending in a forward slash
RewriteCond %{REQUEST_URI} !/\d+$ Why not? Where were the slashes excluded?
I assumed the RewriteCond served as a kind of if() statement. If these conditions are met, (only) then consider this RewriteRule.
In !/\d*$ (that's a regex, not a curse word),