faqts : Computers : Internet : Web Servers : Apache

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

20 of 28 people (71%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How do I make a URL not require a trailing "/"? Example: http://www/testdir, instead of http://www/testdir/

Aug 21st, 2001 14:27
Bruce Christensen, Scott Campbell, http://www.engelschall.com/pw/apache/rewriteguide/#ToC7


The short answer is to add the following to your httpd.conf file:
RewriteEngine  on
RewriteBase    /
RewriteCond    %{REQUEST_FILENAME}  -d
RewriteRule    ^(.+[^/])$           $1/ [R]
Then make sure that you're loading mod_rewrite (or that it's compiled
into Apache).
This basically says that when:
1. The requested file is a directory, and
2. the URL doesn't end in a slash
to add a slash. This causes an external redirect (using the Location
HTTP header).