Skip to main content

Posts

Showing posts from March 6, 2012

Adding A Trailing Slash To A Zend Framework URL

 "We need all our URL's to have a trailing slash", was a request I had in recently. This sounds easy enough, a quick rewrite rule will do the trick, and that is what I added. RewriteRule ^(.*[^/])$ /$1/ [R=301,L] I look at the start of the URL, grab every character to the end of the URL, making sure the last one isn't a slash already, then rewrite that with slashes around it, issuing a 301 redirect and informing Apache not to process any more rules. This works great for pages already on the server, for example /guestbook becomes /guestbook/ . However, what if we wanted to load /logo.gif , this would rewrite to /logo.gif/ and cause a error. OK, so we need not to match every character in the URL, but only if it doesn't have a dot in there. The site in question was a Zend Framework application, and this caused it's own problems. Zend Framework applications have their own rewriting rules... RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQU...