Jason Leveille's Blog
Web Development Intoxication
Now Viewing
Fri, 23 Oct 2009 18:09:27 +0000 1 Comment
I recently had the need to add a trailing slash to http requests in a Concrete5 application (that did not have pretty urls enabled). The issue stemed from clients adding links that did not include the trailing slash. In the interest of keeping things clean, here are the rules I wanted to follow:
Valid characters include: upper and lower a-z, 0-9, forward slashes, and underscores and dashes. Here is what I came up with. If you see a fault, or can improve what is here, please do so.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# If the request contains index.php
RewriteCond %{REQUEST_FILENAME} index.php
# index.php must be preceeded by a forward slash
# and one or more word characters including forward slashes and dashes
# If the pattern contains questions marks, periods, etc, than this condition
# will not be satisfied. The pattern should not contain a trailing
# forward slash
RewriteCond %{REQUEST_URI} index\.php[\/]{1}[a-zA-Z0-9\/_-]+[^\/]$
# Append a trailing forward slash to the request and redirect
RewriteRule ^(.*)$ http://%{SERVER_NAME}/$1/ [L,R=301]
</IfModule>
Comments have been disabled for this post.
1 Comment for "Concrete5 Mod Rewrite to Add Request Trailing Slash"
Comment 1
Jeffrey Brown