Trailing slash 301 redirect code
-
Hi,
I have code for redirecting trailing slash to non-trailing slash, which works fine:
RewriteCond %{HTTP_HOST} !^.yourdomain.co.uk$ [NC]RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
(got code from http://googlewebmastercentral.blogspot.com/2010/04/to-slash-or-not-to-slash.html)
But I cant find a code for redirecting to the trailing slash version anywhere, and I cant modify the above code myself.
Can someone help resolve this issue please, or point me to a resource.
Thanks very much
James
-
Hi Keri,
Thanks for the suggested solution. The enarion solution works for my regular URL's but then causes me issues with some of the more complicated javascript/ajax functionality on the site. No idea why, (bit over my head to be honest) but my developer suggested that it wasnt a good idea to it anyway (again ,for reasons I dont fully understand!)
-
I use Wordpress and Thesis and have them do all the work for me, so I'm not a hands-on expert and can't verify the accuracy of the following URLs, but it looks like they may address your questions. Let us know if one of these works for you.
http://enarion.net/web/htaccess/trailing-slash/
http://soulpass.com/2008/01/11/htaccess-add-trailing-slash-to-url/ (be sure to read whole post)
-
no, google can (and often does) index both pages as separate URL's
-
Hi Rene,
Sorry for the delay in getting back to you. It's this one "/".
I'm not in favour of using the canonical tag as it's not a directive, so I want ideally a 301 redirect code for it
thanks
-
the reson is: Back in the day (I do not know if it still does this, havent tested it or had cause to do so.) google indexed example.com/page/ and example.com/page as two different pages.
The quick fix is to make a RegEx that "tests for the excistense of a trailing slash at the end ofg the url" and then use that in your .htaccess to redirect all urls without to an url with. In other words add a trailing slash. (makes sence I hope.)
You could do the same thing with rel=canonical (even easier imo. since you can use php and do it in the relevant templates)
Here is Matts word on trailing slashes: http://www.mattcutts.com/blog/seo-advice-url-canonicalization/#comment-8260
-
Then why it is suggested to have one version - with or without trailing slash ?
-
In my experience no
-
If a URL has trailing slash ( / ), and a user types the URL without trailing slash, would an 404 error will be shown ?
-
I could probably be of service but since I'm Danish You'll have to give me an example of a "trailing" slash.. A guess it's a slash that tips the left? eg: "" or is it this one: "/"
if you help me understand what you mean I might be able to help you
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
What to do with old content after 301 redirect
I'm going through all our blog and FAQ pages to see which ones are performing well and which ones are competing with one another. Basically doing an SEO content clean up. Is there any SEO benefit to keeping the page published vs trashing it after you apply a 301 redirect to a better performing page?
Technical SEO | | LindsayE0 -
I have lose my ranking Via 301 Redirection - How To Recover?
Hey, Folks! I Have Used 301 Redirection Method to Increase My Rankings but When i applied this Method My Website Ranked Down To 55 Numbers. Can anyone Suggest me How to Recover it?
Technical SEO | | SumitJiGupta0 -
301 Redirect Review Nodes
I have a client who rents out vacation beach rentals. They currently have thousands of homes under management. Each property has its own internal reviewing platform. Reviews are not really intended to be viewed on their own, as in a stand alone page with just the review on it. The problem is that Drupal makes just about every type of node viewable on its own dedicated URL. I was just thinking about taking request to view stand alone reviews and 301’ing them to their respective property page, the context in which they are intended to be viewed. The website has about 2500 review nodes currently crawlable via Drupal that sit on their own URLs. Would there be a material impact to 301 them to their respective property page when any attempt to view them on their own is made to the site?
Technical SEO | | conversionpipeline20 -
How to force Wordpress to remove trailing slashes?
I've searched around quite a bit for a solution here, but I can't find anything. I apologize if this is too technical for the forum. I have a Wordpress site hosted on Nginx by WP Engine. Currently it resolves requests to URLs either with or without a trailing slash. So, both of these URLs are functional: <code>mysite.com/single-post</code> and <code>mysite.com/single-post/</code> I would like to remove the trailing slash from all posts, forcing mysite.com/single-post/ to redirect to mysite.com/single-post. I created a redirect rule on the server: ^/(.*)/$ -> /$1 and this worked well for end-users, but rendered the admin panel inaccessible. Somewhere, Wordpress is adding a trailing slash back on to the URL mysite.com/wp-admin, resulting in a redirect loop. I can't see anything obvious in .htaccess. Where is this rule adding a trailing slash to 'wp-admin' established? Thanks very much
Technical SEO | | james-tb0 -
Trailing Slashes and SEO
Hi, We're currently using a third party blog platform (Blog Engine) on our site and we have a trailing slash issue. I can add as many trailing slashes as I want to the blog's homepage URL, but they don't redirect and our dev guys say this cannot be done with Blog Engine. We're in the process of building our own blog but, in the meantime, I just wanted to know if this will cause an issue? Individual blog posts with trailing slashes are redirected, it's just the homepage where it can't be done. I haven't noticed any traffic going to a blog URL with trailing slashes, and I don't believe any URLs with trailing slashes are being indexed, so should this be OK? Cheers, Lewis
Technical SEO | | PeaSoupDigital0 -
301 Redirect
Hello Moz Community, I have a question regarding 301 redirecting a new domain that contains keywords relevant to my website. However, I do NOT want to change my current domain. My main question is, by just redirecting this new domain to my current website, will those keywords in the new domain help with ranking in anyway? Thanks in advance for any help!
Technical SEO | | WyzeOwl0 -
Does 301 redirecting a site multiple times keep the value of the original site?
Hi, All! If I 301 redirect site www.abc.com to www.def.com, it should pass (almost) all linkjuice, rank, trust, etc. What happens if I then redirect site www.def.com to www.ghi.com? Does the value of the original site pass indefinitely as long as you do the redirects correctly? Or does it start to be devalued at some point? If anyone's had experience redirecting a site more than once and they've seen reportable good/bad/neutral results, that would be very helpful. Thanks in advance! -Aviva B
Technical SEO | | debi_zyx0 -
Wordpress 301 redirects
I use wordpress as CMS on a few sites and I noticed that word press automattically places 301s if I change a url etc. I believe it does it by having the following in the .htaccess file: BEGIN WordPress<ifmodule mod_rewrite.c="">RewriteEngine OnRewriteBase /RewriteRule ^index.php$ - [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]</ifmodule> END WordPress Should I use this? I feel like it limits my control over the 301s.
Technical SEO | | mmaes0