Question about 301 redirect for trailing / ?
-
I am cleaning up a fairly large site.
Some pages have a trailing slash on the end some don't. Some of the existing backlinks built used a trailing slash in the url and some didn't.
We aren't concerned with picking a particular one but just want to get one set and stick to it from now on.
I am wondering, would I clean this up within the same redirect in the htaccess file that takes care of the www and non www?
example
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.domain.com/ [NC]
RewriteRule ^(.*)$ http://domain.com$1 [L,R=301]I currently use that to redirect the www. to the non www as you can see. However here is what I was confused about.
Would this code be enough to redirect ALL pages with a / to the ones without?
or would I also need to add another code (so there is 2) to my htaccess like below?
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain.com/ [NC]
RewriteRule ^(.*)$ http://domain.com$1 [L,R=301]RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.domain.com/ [NC]
RewriteRule ^(.*)$ http://domain.com$1 [L,R=301]That way, now, even the non www pages with a trailing slash will redirect to the non www without the trailing slash.
Hopefully you understand what I am getting at. I just want to redirect EVERYTHING to the non www WITHOUT a /
Thank you
Jake
-
Hmm Well, I'm not that technical either, I just know a little bit about 301's
Try this in stead of the second code snippet:
RewriteCond %{HTTP_HOST} !^\.domain\.com$ [NC] RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
-
Thanks Yannick,
Quick question, I have dropped both snippets into the htaccess file. When I view my url in internet explorer it still has the trailing slash. All instances of the www. have been removed however. Is this just something IE does leaving the trailing slash even if it is in fact being redirected?
Is there a tool or a way to check to make sure the action has been completed correctly?
Thanks again for the help, this technical stuff is NOT my background.
-
The one with the 2 code snippets is the one you needl! You just have to realize: what is accessed more often: the www version of a page or the / version of your pages? This speeds up apache a bit if the one that is accessed most is on top of the other.
Cheers!
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
-
.Com version of my site is ranking better than .co.uk for my UK Website for branded search. 301 redirect mess
Dear Mozzers, I have an issue with my UK Website (short url is - http://goo.gl/dJ7IgD ) whereby when I type my company name in to google.co.uk search the .com version returns in Search as opposed to the .co.uk and from looking at open site explorer the page rank of the .com is higher than the .co.uk ?. Infact I cant even see the .co.uk homepage version but other pages from my site. The .com version is also 301'd to the .co.uk. From looking at Open Site Explorer, I have noticed that we have more links pointing to .com as opposed to .co.uk. Alot of these are from our own separate microsites which we closed down last year and I have noticed the IT company who closed them down for some reason 301'd them to the .com version of our site as opposed to the .co.uk but If I look in http://httpstatus.io/ (http status checker tool) to check one of these mircosites it shows - 301 - 302 - 200 status codes which to me looks wrong ?. I am wondering what it should read ... e.g should it just be a 301 to a 200 status code ?. My Website short url is - http://goo.gl/dJ7IgD and an example of some of 10 microsites we closed down last year which seems to be redirected to .com is http://goo.gl/BkcIjy and http://goo.gl/kogJ02 As these were redirected almost a year ago - it is okay if I now get them redirected to the .co.uk version of my site or what should I do ? They currently redirect to the home page but given that each of the microsites are based on an individual category of my main site , would it be better to 301 them to the relevant category on my site. My only concern is that , may cause to much internal linking and therefore I wont have enough links on my homepage ? How would you suggest I go about building up my .co.uk authority so it ranks betters than the .com- I am guessing this is obviously affecting my rankings and I am losing link juice with all this. Any advice greatly appreciated . thanks Pete
Intermediate & Advanced SEO | | PeteC120 -
If you do 302 redirect then change to 301 redirect do you lose all link juice?
Hello everyone, I was wondering if you could help me with understanding the following story: A website has been moved from its HTTP version to a HTTPS version. The SEO manager has advised developers that they needed to do 301 redirects. However, in the end, 302 redirects have been put in place instead. Now, 301s should be put in place ASAP. The million dollar question is: has the website lost all of its link juice already given the nature of the redirects? Also, does it depend on whether Google has indexed the new 302 pages or does it depend on something else? Many thanks!
Intermediate & Advanced SEO | | MarketingGH0 -
How is my 301 redirected site stealing rankings from the main site?
Hello, I have a site, drhobelt.com, that 301 redirects to the main site, drhonow.com. Not only is drhobelt.com still indexed, but it recently stole rankings from drhonow.com for "decompression belt" related terms. What could be causing this? How do I reclaim the rankings for drhonow.com? Thanks for reading!!
Intermediate & Advanced SEO | | DA20130 -
301 redirect recommendations
One of our clients we are working on have two sites the main with a PR5 and a separate one with a PR4. We are planning on doing a 301 from the PR4 to a page on the PR5 Is it best to do: www.PR4.com ----> www.PR5.com/releveantPR4page or www.PR4.com/page ----> www.PR5.com/releveantPR4page Most pages on the PR4 site can fit into one PR5 page logically. However the PR4 has an about us, contact us, blog/with posts, FAQ, Applications, Legal Resources which are all pretty out dated.. The PR4 site is kinda messy and we are not sure if it will be easy to 301 each page individually with the user in mind. can we do a sitewide 301 redirect from the root PR4.com to a page PR/5.com/releveantPR4page and also do deeper 301's? PR4.com/PR4page ---> PR5.com/releveantPR4page
Intermediate & Advanced SEO | | Bryan_Loconto0 -
301 Redirecting an Entire Site
I have a question which has had me thinking for hours..... If SITE A is ranking well on a number of search phrases and you 301 that site to another (SITE B). The site will change on the Google SERPs to the site which you've re-directed to... In this case SITE B. But how do you maintain the rankings of SITE A?. Do you keep the rankings of SITE A forever? Or will your rankings of SITE A (now SITE B) gradually slip as other sites rank higher? As you can no longer edit SITE A does Google take into consideration the content on SITE B and no longer take anything that SITE A had to offer into consideration? SITE B has simply replaced it in the SERPs??...... Please can anybody help? Thanks,
Intermediate & Advanced SEO | | karl620 -
301 Re-Directs Puzzling Question on Page Returned in Search Results
On our website, www.BusinessBroker.net, we have 3 different versions of essentially the same page for each of our State Business for Sale Pages. Back in August, we did a test and did 301 redirects using 5 States. For a long while after doing the redirects, the pages fell out of Google search results - we used to get page 1 rankings. Just recently they started popping back up on Page 1. However, I noticed that the new page meta data is not what is being picked up -- here is the example. Keyword Searched for in Google -- "Maine Business for Sale" Our listing shows up on Page 1 -- # 8 Result URL returned is correct preferred version: - http://www.businessbroker.net/state/maine-Businesses_For_Sale.aspx However, the Page Title on this returned page is still the OLD page title - OLD TITLE -- maine Business for Sale Ads - maine Businesses for Sale & Business Brokers - Sell a Business on Business Broker Not the title that is designated for this page - New Title - Maine Businesses for Sale - Buy or Sell a Business in ME | BusinessBroker.net Ditto for Meta Description. Why is this happening? Also have a problem with lower case showing up rather than upper case -- what's causing this? http://www.businessbroker.net/state/maine-Businesses_For_Sale.aspx versus -- http://www.businessbroker.net/State/Maine-Businesses_For_Sale.aspx Any help would be appreciated. Thanks, MM
Intermediate & Advanced SEO | | MWM37720 -
How to Redirect
What is the htaccess code to redirect everything in a directory to a file? Thanks!
Intermediate & Advanced SEO | | tylerfraser0 -
Help Needed - 301 a .co.uk to a .com Serp Questions
Hey, really need some help deciding what to do... I have a .co.uk site, its my oldest and best site of my network and accounts for maybe 30-40% of my income. Although its a .co.uk site, it actually makes most of its from from USA traffic and targets many terms for the US market - but the problem is that due to it being a .co.uk it doesnt rank as well in G .com and over the last few years Google has defiantly widened the gap as such for the ability for a .co.uk to rank in G .com. Many terms that I used to be #1 for in G .com, I now rank position 5-10 only, but in G .co.uk I'm #1 and often with a duo listing so I wouldnt put the loss of rankings in G .com down to just losing rankings naturally. Now many of my key pages are gradually losing rankings in G .com which is not good and really frustrating Feedback Needed So my dilemma is do I risk my best site and 301 it to a .com hosted in the US for potential at a guess 50% increase in revenues and more future potential (If the 301 worked well and got some US rankings back - Im sure longtail would increase lots too) ? If people with experience with 301ing sites to a new domain could let me know how they did or if you're an SEO and have done this many times, how many times on average has Serps remained stable / unchanged ? Trying to work out the reward to risk ratio, like on average if the transition is seamless 90% of the time it would seem worth the gamble, but if its 50% then I would say its not worth it.
Intermediate & Advanced SEO | | goody2shoes0