Welcome to WebmasterWorld Guest from 54.204.74.171

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Return 301 for trailing slash

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

5+ Year Member



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 Jun 21, 2012 (gmt 0)

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



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 Jun 21, 2012 (gmt 0)

5+ Year Member



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 Jun 23, 2012 (gmt 0)

5+ Year Member



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 Jun 23, 2012 (gmt 0)

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



!^(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.