homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Return 301 for trailing slash

 5:20 pm on Jun 21, 2012 (gmt 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 Jun 21, 2012 (gmt 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 Jun 21, 2012 (gmt 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 Jun 23, 2012 (gmt 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 Jun 23, 2012 (gmt 0)


:: 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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved