Mod_rewrite help needed

Discussion in 'Apache' started by Jim_Westergren, Jan 24, 2006.

  1. #1
    I need a line in my .htaccess which would redirect all URLs that does not end with the trailing dash to one.

    One of my link builders did a very stupid mistake.

    She built up links for http://www.jimwestergren.com/v7ndotcom-elursrebmem

    Instead of http://www.jimwestergren.com/v7ndotcom-elursrebmem/ (the URL I gave)

    Which is total different URLs by Google.

    Evidence:

    http://www.mattcutts.com/blog/seeing-nofollow-links/ PR 5
    http://www.mattcutts.com/blog/seeing-nofollow-links PR 0

    So the list of PR 3-5 links I got from her are all useless and can only cause damage. :confused:

    Thanks for helping me on this.

    I could of course just make a 301 on only this example but would be good to make it on all posts for similar links in the future.
     
    Jim_Westergren, Jan 24, 2006 IP
  2. tkluge

    tkluge Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    tkluge, Jan 24, 2006 IP
  3. nevetS

    nevetS Evolving Dragon

    Messages:
    2,544
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    135
    #3
    nevetS, Jan 24, 2006 IP
  4. Jim_Westergren

    Jim_Westergren Notable Member

    Messages:
    1,882
    Likes Received:
    247
    Best Answers:
    0
    Trophy Points:
    235
    #4
    Thanks a lot both of you.

    These lines were the solution:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(.*)/$
    RewriteRule ^(.*)$ http://www.jimwestergren.com/$1/ [L,R=301]

    My .htaccess file is now 9,52 KB big, I hope it does not slow down the site ...

    I will blog soon about this, it is vital for all wordpress users.
     
    Jim_Westergren, Jan 24, 2006 IP
  5. hulkster

    hulkster Peon

    Messages:
    1,705
    Likes Received:
    93
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I'm confused ... doesn't the web server do the redirect for you automatically?

    MSN and Yahoo drop trailing slashes from their SERP results, so in my web logs, I see this type of stuff all the time. I'm running Apache as a web server.

    So ideally it should be taken care of automatically ... although I've always wondering if the internal algorithms of the search engines realize this - yea, best to fix at the source if at all possible.
     
    hulkster, Jan 24, 2006 IP
  6. tkluge

    tkluge Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    This is only problematic if not the webserver but a script that is not written with that in mind handles the request.

    Normally the webserver would do the redirect automatically.

    I don't know why this only affects MSN and Yahoo(but not Google), probably they have some other heuristics (nice word, I like it. Doesn't describe what it means, just some fuzzy functionality).

    Tobias
     
    tkluge, Jan 24, 2006 IP