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
-
Using a Reverse Proxy and 301 redirect to appear Sub Domain as Sub Directory - what are the SEO Risks?
We’re in process to move WordPress blog URLs from subdomains to sub-directory. We aren’t moving blog physically, but using reverse proxy and 301 redirection to do this. Blog subdomain URL is https://blog.example.com/ and destination sub-directory URL is https://www.example.com/blog/ Our main website is e-commerce marketplace which is YMYL site. This is on Windows server. Due to technical reasons, we can’t physically move our WordPress blog to the main website. Following is our Technical Setup Setup a reverse proxy at https://www.example.com/blog/ pointing to https://blog.example.com/ Use a 301 redirection from https://blog.example.com/ to https://www.example.com/blog/ with an exception if a traffic is coming from main WWW domain then it won’t redirect. Thus, we can eliminate infinite loop. Change all absolute URLs to relative URLs on blog Change the sitemap URL from https://blog.example.com/sitemap.xml to https://www.example.com/blog/sitemap.xml and update all URLs mentioned within the sitemap. SEO Risk Evaluation We have individual GA Tracking ID and individual Google Search Console Properties for main website and blog. We will not merge them. Keep them separate as they are. Keeping this in mind, I am evaluating SEO Risks factors Right now when we receive traffic from main website to blog (or vice versa) then it is considered as referral traffic and new cookies are set for Google Analytics. What’s going to happen when its on the same domain? Which type of settings change should I do in Blog’s Google Search Console? (A). Do I need to request “Change of Address” in the Blog’s search console property? (B). Should I re-submit the sitemap? Do I need to re-submit the blog sitemap from the https://www.example.com/ Google Search Console Property? Main website is e-commerce marketplace which is YMYL website, and blog is all about content. So does that impact SEO? Will this dilute SEO link juice or impact on the main website ranking because following are the key SEO Metrices. (A). Main website’s Avg Session Duration is about 10 minutes and bounce rate is around 30% (B). Blog’s Avg Session Duration is 33 seconds and bounce rate is over 92%
Intermediate & Advanced SEO | | joshibhargav_200 -
Penguin and 301 redirects...
Hi, I have several questions about starting a new domain due to Penguin. The site is: http://bajajlaw.com. Quick backstory: This site was hit every time Penguin rolled out. No clean-up was done until October 2015. At that time, I took over the project. My efforts include: (1) Remove'em, (2) manual removal, (3) and the Disavow Tool. The HP went from being at around #50 for the target KW (San Diego criminal defense attorney) to about #25. Never really moved higher than that. However, I redid the content for the internal pages (DV, Theft Crimes, etc.) and they are all ranking fairly well (first page or top of 2nd). In short, the penalty only seems to affect the HP, not the internal pages. Instead of waiting for Penguin to roll-out, client wants to move forward with new domain. My questions are as follow: 1. Can I use the same content for the internal pages and 301 from the old internal pages to the new? 2. Should I 301 from the old to the new domain for the HP, or not? 3. If I do a 301 from an internal page to a new internal page, does that have the same effect of doing a 301 from the old HP to the new HP? I have read various opinions on this topic. I'd appreciate feedback from anyone who has experience doing this sort of thing. Thanks. P.s. I'm inclined to wait for P4 to rollout, but given that nobody seems to know when that might be, it's hard for me to advise client to keep waiting for it.
Intermediate & Advanced SEO | | mrodriguez14400 -
301 or Canonical - Ecommerce Site Question
We are making a change to our Navigation and this includes having to change the URL structure of a few pages of our site. Due to issues with the CMS (that are out of my control) we are unable to keep the current URL structure of two of our highest ranking pages. Our site is an E-commerce Site The Structure is changing from..... www.domain.com/page/highrankingpage <----OLD PAGE RANKED WELL to www.domain.com/category/highrankingpage <----NEW PAGE Generally I would have 301 'd this page but I found out that our Tech team added a Canonical to this page instead....(showing the high ranking page to the Search Engines) and on our site the visitors are able to browse the website getting the new page. BOTH PAGES ARE BASICALLY IDENTICAL (Same Content) http://searchenginewatch.com/sew/how-to/2288690/how-and-when-to-use-301-redirects-vs-canonical# Thoughts?
Intermediate & Advanced SEO | | CMcMullen0 -
Is it safe to 301 redirect old domain to new domain after a manual unnatural links penalty?
I have recently taken on a client that has been manually penalised for spammy link building by two previous SEOs. Having just read this excellent discussion, http://www.seomoz.org/blog/lifting-a-manual-penalty-given-by-google-personal-experience I am weighing up the odds of whether it's better to cut losses and recommend moving domains. I had thought under these circumstances it was important not to 301 the old domain to the new domain but the author (Lewis Sellers) comments on 3/4/13 that he is aware of forwards having been implemented without transferring the penalty to the new domain. http://www.seomoz.org/blog/lifting-a-manual-penalty-given-by-google-personal-experience#jtc216689 Is it safe to 301? What's the latest thinking?
Intermediate & Advanced SEO | | Ewan.Kennedy0 -
Cannot 301 redirect, alternatives?
Hi, the company has changed it's name so now under a different domain. All pages have been 301 redirected on a 1:1 basis apart from the home page. For some reason IT cannot 301 redirect the old home page to the new website home page. At suggestions? Perhaps canonical it? Meantime the old home page copy has been changed to say the company name has changed and a link to the new website. Any help greatly appreciated.
Intermediate & Advanced SEO | | Richard5550 -
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 -
Should i continue linking the old page after a redirect 301?
hi everybody, i'm trying to understand why my page http://poltronafraubrescia.zenucchi.it isn't ranked for the keyword poltrona frau brescia even if is indexed on google. the page gets authority and traffic from the page www.zenucchi.it/ITA/poltrona-frau-brescia.html that is already ranked in fourth position for that keyword. should i continue linking the previous or the new page to increase the page authority? i don't know if is a good way to link a page not ranked despite a ranked one.. Please help me.... thanks a lot
Intermediate & Advanced SEO | | guidoboem0 -
Is there a way to find out how many 301 redirects a site gets?
If you do a search on "personal loans" on Google the first non-local/personal result is onemainfinanical.com. They have far fewer links showing in OSE and YSE than the other sites. I know onemainfinanical.com is a Citbank site so I'm trying to determine if they are ranking so high b/c they are getting 301 link juice from old Citibank.com authority pages. Is there anyway to check to see what sites are sending link juice through a 301 redirect instead of a direct link?
Intermediate & Advanced SEO | | fthead90