• If you don’t know what I’m talking about, then, you can probably ignore this thread. I came across some code that I thought would help some WordPress users that don’t like what Yahoo does in serps listings. Basically, Yahoo lists their links without the trailing slash. So, if someone is coming from Yahoo, they would hit example.com/directory instead of example.com/directory/. It was driving me crazy, so, I hope this helps out someone else. Drop this in your .htaccess file and change the example url.

    # If requested resource does not exist as a file
    RewriteCond %{REQUEST_FILENAME} !-f
    # and does not end with a period followed by a filetype
    RewriteCond %{REQUEST_URI} !..+$
    # and does not end with a slash
    RewriteCond %{REQUEST_URI} !/$
    # then add a trailing slash and redirect
    RewriteRule (.*) http://www.example.com/$1/ [R=301,L]

    Thanks to mexicoshanty via this thread.

Viewing 2 replies - 1 through 2 (of 2 total)
  • To make the above work I had to (and I think you will too) change the line:
    RewriteCond %{REQUEST_URI} !..+$

    to:
    RewriteCond %{REQUEST_URI} !\..+$

    This is because in regular expressions the . character has a meaning. Escaping it with \ makes it a literal ‘.’.

    Thread Starter damage

    (@damage)

    dbenton, been a long time since I hit this thread, but, you are absolutely right. I checked my .htaccess file and I also had that revision. Maybe I just didn’t type it right in the beginning. Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Adding Trailing Slash for Yahoo using .htaccess’ is closed to new replies.