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
-
301 Redirects Backlinks?
I am wondering how many people still getting results from 301 redirects from high authority expired domains..? I read few case studies on detailed dot com where the shared some people still making big bucks from this strategy which i think 10beast also implemented few years back.? Is it worth it to test out 301 redirects to money sites.? How many people on the moz community here have implemented this strategy in practical and can share some insights and pros and cons of doing 301 redirects? Many Thanks.
Technical SEO | | asifseo0980 -
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 Redirects in subfolders
Hi, we're making our site into a static site but I would like to transfer the Google juice. Most of the links and database exist on subfolders though. Could I simply do 301 redirects on the subfolders and retain the value or does it have to be on the full domain?
Technical SEO | | Therealmattyd0 -
To avoid errors in our Moz crawl, we removed subdomains from our host. (First we tried 301 redirects, also listed as errors.) Now we have backlinks all over the web that are broken. How bad is this, from a pagerank standpoint?
Our MOZ crawl kept telling us we had duplicate page content even though our subdomains were redirected to our main site. (Pages from Wineracks.vigilantinc.com were 301 redirected to vigilantinc.com/wineracks.) Now, to solve that problem, we have removed the wineracks.vigilantinc.com subdomain. The error report is better, but now we have broken backlinks - thousands of them. Is this hurting us worse than the duplicate content problem?
Technical SEO | | KristyFord0 -
Delete 301 redirected pages from server after redirect is in place?
Should I remove the redirected old pages from my site after the redirects are in place? Google is hating the redirects and we have tanked. I did over 50 redirects this week, consolidating content and making one great page our of 3-10 pages with very little content per page. But the old pages are still visible to google's bot. Also, I have not put a rel canonical to itself on the new pages. Is that necessary? Thanks! Jean
Technical SEO | | JeanYates0 -
How long should you keep 301 redirects?
Hi, Back in 2009 I decided to update an older site from .htm and .shtml to .php. In order to minimize the impact I would go in every month and do a 301 redirect on the .shtml page to the new .php page. So I have many that range from 2009 through 2010. I had left the old 301's because I felt they would only be used if needed but I would think I should clean up my .htaccess by removing the old 301 redirects if they are not needed. How long should you keep this type of 301 redirect? Thanks!
Technical SEO | | Force70 -
301 redirect
What is a proper way to redirect any url containing a give word (anywhere in the url) to another sepcified url? Is it like this? RedirectMatch 301 ^thisword$ http://domain.com/newlocation
Technical SEO | | sesertin1 -
301 redirect on the root of the site
Due to some historic difficulties with our URL Rewriter, we are in the position of having the root of our site 301 redirected to another page. So the root of our site: http://www.propertylive.co.uk/ has a 301 redirect to: http://www.propertylive.co.uk/home.aspx We're aware that this isn't great and we're working to fix this completely, but what impact will this have on our SEO?
Technical SEO | | LianWard860