DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

.htaccess That Fixes The Trailing Slash Error

  • submit to reddit
        // This .htaccess file is for use with a Rails application that is accessed by a symbolic link. This fixes an error in which the directory URL must have a trailing slash. Otherwise, the user receives a 400 Bad Request error.

Options +FollowSymLinks +ExecCGI

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME}    -d
RewriteCond %{SCRIPT_FILENAME}      ^.*[^\/]$
RewriteRule ^(.*)$ $1/ [N]

#Put the directory your Rails app is in here.
RewriteBase /directory

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.cgi?$1 [QSA,L]


Snippets Manager replied on Mon, 2012/05/07 - 2:34pm

I too had got this problem on my hosted with I could not fix it. Nice to see this solution! :)

Snippets Manager replied on Mon, 2012/05/07 - 2:34pm

I first had this problem about 18 months ago. I didn't fix it this same way, but I am so glad someone has actually come up with a NICE way to fix it :)