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
-
Is domain authority lost if you create a 301 redirect but mark it as noindex, nofollow?
Hi everyone, Our company sells products in various divisions. While we've been selling Product A and Product B under our original brand, we've recently created a new division with a new domain to focus on a Product B. The new domain has virtually no domain authority (3) while the original domain has some (37). We want customers to arrive on the new domain when they search for key search terms related to Product B instead of the pages that previously existed on our main website. If we create 301 redirects for the pages and content on the main site and add noindex, nofollow tags, will we lose the domain authority that we have from our original domain because the pages now have the noindex, nofollow tags? I read a few blog posts from Moz that said there isn't any domain authority lost with 301 redirects but I'm not sure if that is true if the pages are noindex, nonofollow. Do you follow? 🙂 Apologies for the lengthy post. Love this community and the great Moz team. Thanks, Joe
Intermediate & Advanced SEO | | jgoehring-troy0 -
If my website uses CDN does thousands of 301 redirect can harm the website performance?
Hi, If my website uses CDN does thousands of 301 redirect can harm the website performance? Thanks Roy
Intermediate & Advanced SEO | | kadut1 -
How to speed up transition towards new 301 redirected landing pages?
Hi SEO's, I have a question about moving local landing pages from many separate pages towards integrating them into a search results page. Currently we have many separate local pages (e.g. www.3dhubs.com/new-york). For both scalability and conversion reasons, we'll integrate our local pages into our search page (e.g. www.3dhubs.com/3d-print/Bangalore--India). **Implementation details: **To mitigate the risk of a sudden organic traffic drop, we're currently running a test on just 18 local pages (Bangalore) = 1 / 18). We applied a 301 redirect from the old URL's to the new URL's 3 weeks ago. Note: We didn't yet update the sitemap for this test (technical reasons) and will only do this once we 301 redirect all local pages. For the 18 test pages I manually told the crawlers to index them in webmaster tools. That should do I suppose. **Results so far: **The old url's of the 18 test cities are still generating > 99% of the traffic while the new pages are already indexed (see: https://www.google.nl/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=site:www.3dhubs.com/3d-print/&start=0). Overall organic traffic on test cities hasn't changed. Questions: 1. Will updating the sitemap for this test have a big impact? Google has already picked up the new URL's so that's not the issue. Furthermore, the 301 redirect on the old pages should tell Google to show the new page instead, right? 2. Is it normal that search impressions will slowly shift from the old page towards the new page? How long should I expect it to take before the new pages are consistently shown over the old pages in the SERPS?
Intermediate & Advanced SEO | | robdraaijer0 -
Hundreds of 301 Redirects. Remove Pages or Not?
Hi Mozers, I have a website that has literally got hundreds of 301 redirects. I had a close look at these URLs and only some of them have backlinks to it and remaining all of them are not indexing in Google and has got not backlinks at all. Based on what I have noticed experts mentioning, loads of 301 redirects can potentially slow down the site speed. In a case like the website I have, should I completely take off the pages from website to reduce the number of 301 redirects or should I leave 301 redirects? There is no traffic or backlinks coming from these URLs. Malika
Intermediate & Advanced SEO | | Malika10 -
Technical 301 question
Howdy all, this has been bugging me for a while and I wanted to know the communities ideas on this. We have a .com website which has a little domain authority and is growing steadily. We are a UK business (but have a US office which we will be adapting too soon) We are ranking better within google.com than we do on google.co.uk probably down to our TLD. Is it a wise idea to 301 our .com to .co.uk for en-gb enquiries only? Is there any evidence that this will help improve our position? will all the link juice passed from 301s go to our .co.uk only if we are still applying the use of .com in the US? Many thanks and hope this isn't too complicated! Best wishes,
Intermediate & Advanced SEO | | TVFurniture
Chris0 -
To Redirect or Not
I have a strange situation and looking for advice on how well a permanent redirect of url will work. I have an eCommerce site called twpstain.com. This site sells TWP Deck stain and the URL/Content is fully owned by me. We do not however own the TWP brand and have always operated with permission from the manufacturer as an Authorized dealer. Circumstance have come up where they now want to be in control of all URLS that have the name "TWP" in them. Not sure if they legally can do this but they can cut me off with product if I do not comply. My options are: 1. A permanent redirect of entire site to new URL that does not have the word "TWP" in the url. 2. Give them the URL but they are willing to have me use the URL as I have in the past. A contract for this would be drawn up to cover me for years to come and possibly offer compensation if they decide not to renew. My concerns are numerous but the question for the Moz community is to how well the 301 redirect will work and will I lose my rankings? I currently dominate the rankings for my site and I very concerned that there will be major loss of sales and traffic. Any help or opinions on this would be much appreciated.
Intermediate & Advanced SEO | | dogtopiamichigan0 -
Organic keywords have dropped significantly in a short time period when relaunching site, but all 301 redirects are working properly.
We redesigned a site and relaunched it on the same domain. All 301 redirects were completed and are working properly. Around the same time, they fired an seo company who was published inbound links to their site on spammy directories (and this was during the same time period that Google's Hummingbird algorithm change took place). After the website relaunch, their keyword rankings fell off dramatically; and in all of our research, we're not seeing what has caused this issue. I'm not seeing any red flags in their moz reports or even in their google analytics traffic; but organic keywords are way down, and now leads from organic traffic are also way down. Help??
Intermediate & Advanced SEO | | grapevinemktg0 -
301 - should I redirect entire domain or page for page?
Hi, We recently enabled a 301 on our domain from our old website to our new website. On the advice of fellow mozzer's we copied the old site exactly to the new domain, then did the 301 so that the sites are identical. Question is, should we be doing the 301 as a whole domain redirect, i.e. www.oldsite.com is now > www.newsite.com, or individually setting each page, i.e. www.oldsite.com/page1 is now www.newsite.com/page1 etc for each page in our site? Remembering that both old and new sites (for now) are identical copies. Also we set the 301 about 5 days ago and have verified its working but haven't seen a single change in rank either from the old site or new - is this because Google hasn't likely re-indexed yet? Thanks, Anthony
Intermediate & Advanced SEO | | Grenadi0