.htaccess - trailing slash problem

Discussion in 'Site & Server Administration' started by AEDUP, Jun 28, 2010.

  1. #1
    on one of my sites, whenever you don't include a trailing slash on anything past the main page, you get:

    (music, for example)
    I need the site to automatically add an ending slash if a user doesn't, so that they don't get that error of course. How might I go about this?

    the code i'm using is:
    RewriteEngine on
    RewriteCond %{http_host} ^domain.com [nc]
    RewriteRule (.*)$ http://www.domain.com/$1 [r=301,nc]
    Code (markup):

    I've tried this approach by substitution:

    http://www.webmasterworld.com/forum92/5117.htm

    Which looks like this:
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !(\.¦/$)
    RewriteRule (.+) http://www.domain.com/$1/ [R=301,L]
    Code (markup):
    But all I get is:

    Help?
     
    AEDUP, Jun 28, 2010 IP
  2. bvsonline

    bvsonline Peon

    Messages:
    83
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi,

    Try this code.

    =========
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(.*)/$
    RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]
    =========
     
    bvsonline, Jun 29, 2010 IP
  3. AEDUP

    AEDUP Member

    Messages:
    62
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    ^ Nice! Thanks, that works like a charm.

    Now I have a different .htaccess question, if you or anyone else could answer.

    When you are a guest on the site, the url's appear normal, like:
    but if you're signed in, it would show:
    And that's a problem. Mainly because if a member is logged in and copies the current url in the address bar, pastes it on another site and that external link is clicked, it will take whoever clicked on it to the login page for whatever they're trying to view (if they're not already signed in on the site). So my question is, is there a way to mask the "/members/" extension in the URL for logged in members, with some sort of .htaccess "trick"?
     
    AEDUP, Jun 30, 2010 IP