Welcome to WebmasterWorld Guest from 54.225.38.176

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Return 301 for trailing slash

     
5:20 pm on Jun 21, 2012 (gmt 0)

New User

10+ Year Member

joined:Sept 8, 2005
posts:35
votes: 0


1. Hi, I have read on Google Webmaster Central that "donít both return a 200 response code, but that one version redirects to the other."

I have checked my URLs and both with trailing slash and non-trailing slash return 200 OK response.

What I want to do now is 301 the other URL like this:
http : // www .mywebsite.com/category/post = 200 OK
http : // www .mywebsite.com/category/post/ = 301 Moved Permanently

While in the directory:
http : // www .mywebsite.com/category/cat-title = 200 OK
http : // www .mywebsite.com/category/cat-title/ = 301 Moved Permanently

I have tried several wordpress plugin for permalink redirect but none work. So, .htaccess would be my last resort. Please tell me how to do this. Thanks in advance.
5:45 pm on June 21, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


This sort of URL handling should be handled in the Wordpress core.

They should never pandered to the "add trailing slashes for SEO" nonsense that was peeddled some years ago, and instead deferred to RFC2616 [Hypertext Transfer Protocol -- HTTP/1.1] which I commend to you as required reading.

The URL for a folder or for the index page of a folder ends with a trailing slash.

The URL for a page does not end with a trailing slash, and may or may not have an optional extension.

The URL for a file will usually end with an extension and certainly not with a trailing slash.

What htaccess code have you tried so far?
11:40 pm on June 21, 2012 (gmt 0)

New User

10+ Year Member

joined:Sept 8, 2005
posts:35
votes: 0


g1smd, I am not much into .htaccess coding, so basically I just search and copy from the Internet. So far I have tries this one but no luck. It still gives 200 on both post URL.

RewriteRule ^(.+[^/])/$ [%{HTTP_HOST}...] [R=301,L]
4:17 am on June 23, 2012 (gmt 0)

New User

10+ Year Member

joined:Sept 8, 2005
posts:35
votes: 0


Finally, this code seems to work. What do you think?

#get rid of trailing slashes
RewriteCond %{HTTP_HOST} ^(www.)?website\.lv$ [NC]
RewriteRule ^(.+)/$ http: // www. website .com/$1 [R=301,L]

I still to test it though, sometimes it works and sometimes not. Could it be a conflict in Cache plugin?
7:15 am on June 23, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13066
votes: 308


!^(www\.example\.lv)?$

:: detour to find out where on earth .lv is ::

Oh, and while I'm looking that up, you can read the Sticky post about using example.com. Or example.lv, if you prefer.