Forum Moderators: phranque

Message Too Old, No Replies

.htaccess

Trailing slash

         

gosman

1:06 am on Dec 10, 2006 (gmt 0)

10+ Year Member



I need need a rewrite that will add a trailing slash and if the trailing slash is the last part of the URL then a 301 to /index.htm is performed.

Example.

If the following was entered in the browser

[mysite.com...]

A 301 would occur to the following.

[mysite.com...]

Any help with the correct syntax would be much appreciated.

jdMorgan

1:33 am on Dec 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



From a recent thread:

# Append "/" if requested URI contains no filetype and does not end in "/"
RewriteCond %{REQUEST_URI} !(\.¦/$)
RewriteRule (.+) http://www.example.com/$1/ [R=301,L]

Redirecting to "/index.html" exposes your site's technology, leaves time-bomb for later if/when you change to say, PHP or ASP, and will show up in search results. As such, it's not usually desirable to do this.

But if you're sure that's what you want, then add "index.html" to the end of the substitution URL in the RewriteRule above.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim