Need Help writing 301 redirects in .htaccess file
-
SEOmoz tool shows me 2 errors for duplicate content pages (www.abc.com and www.abc.com/index.html). I believe, the solution to this is writing 301 redirects
I need two 301 redirects
1. abc.com to www.abc.com
2. /index.html to / (which is www.abc.com/index.html to www.abc.com)
The code that I currently have is
...................................................
RewriteEngine On
RewriteCond %{HTTP_HOST} ^abc.com
RewriteRule (.*) http://www.abc.com/$1 [R=301,L]Redirect 301 http://www.abc.com/index.html http://www.abc.com
......................................................
but this does not redirect /index.html to abc.com. What is wrong here? Please help.
-
I don't recall why, but I don't think you can use a full (absolute) path for the first part of a "Redirect 301" statement Could you try just:
"Redirect 301 /index.html http://www.abc.com"
Typically, the rewrite command (with flag of "R=301") is much more flexible. The "Redirect 301" syntax has some limitations - it's easier to use, but it only covers a few, simple situations.
-
Oh yeah, sorry. The case I was thinking of was when you wanted to detect >everything< (e.g. abc.com/afjsk.htm) and redirect it. If you're only concerned with one case (index.html) Ally's solution is better. Remember that for individual cases you'd have to make an entry for each one (index.htm, index.php, default.htm) if those are becoming issues as well, which I doubt they would be in your case.
-
I'm not a hundred percent on this-but am interested to see what everyone else thinks-So be patient:
I think it should appear as follows:
RewriteEngine On
RewriteCond %{HTTP_HOST} !www.abc.com$[NC]
RewriteRule ^(.*) $http//www.abc.com/$1 [L,R=301]or
Redirect 301 abc.com/index.html http://www.abc.com
Make sure you save your.TXT file with the correct name and to the correct location. I hope this helps. If I have this wrong anyone I would love to know the correct way myself.
Thanks,
Ally
-
I believe you need to have a wildcard at the end too; right now the expression is stopping searching at abc.com instead of looking past it. This is the one I use I think (going from memory) for a similar situation:
RewriteCond %{HTTP_HOST} ^www.abc.com(.*)$ [NC]
The (.*) means 'everything' as a wildcard
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 redirecting a previously abused URL
A client previously had their most important landing page at domain.com/example.htm They carried out the sort of link building that was commonplace a few years back (exact match anchors, paid blog links etc) targeting this URL, but they also got a bunch of legitimate decent quality links here. I believe they may have had a number of issues when link quality algo updates were rolled out, so rather than try and get links removed and go through the disavow process they instead decided to abandon this URL, let it 404 and start afresh at domain.com/example.html - updating all internal navigation, XML sitemaps etc. So fast forward to today. What is the best practice for this URL these days do we think? Is it now possible to 301 domain.com/example.htm > domain.com/example.html and recover whatever value may be left here? The argument for not doing so may be that you could pass over the negative metrics associated with the old URL, but would this not be handled by the real-time penguin update and the poor links just devalued rather than actually harming? And could this just be tested - i.e. add in the 301, monitor the impact and if things don't go the way we'd want then just remove the 301 again? Would be keen to get a few opinions on this. TIA
Technical SEO | | Salience_Search_Marketing0 -
To many 301 redirects
Hi, Is there anything wrong with over 100 301 reditects on my wordpress website and how do you go about redirecting a 301 again for example abc.com redirects to bca.com now i want to redirect bca.com to ert.com any problems with this setup? Regards
Technical SEO | | ReSEOlve0 -
301 redirects- how long to keep and how many are too many?
Hi, I was told we have way too many 301 redirects on our site. We have some that have been there for 3 years. Our site is datacard.com . Question- how long should you keep a redirect out there when building a new page and expiring an old page? Is it 6 months, is it a certain time frame? wondering what the best practices are? Thanks! Laura
Technical SEO | | lauramrobinson320 -
Dupliacate page content from Moz which I need soem help with
Hi Just checked a diagnostic report in moz and we are getting duplicate page content for http://domain.co.uk and http://www.domain.co.uk attached is the screen shot Does anyone know how to fix this in magento? Thanks duplicate.png
Technical SEO | | tidybooks0 -
HTTP 500 Internal Server Error, Need help
Hi, For a few days know google crawlers have been getting 500 errors from our dedicated server whenever they try to crawl the site. Using the "Fetch as Google" tool under health in webmaster tools, I get "Unreachable page" every time I fetch the homepage. Here is exactly what the google crawler is getting: <code>HTTP/1.1 500 Internal Server Error Date: Fri, 21 Jun 2013 19:52:27 GMT Server: Apache/2.2.15 (CentOS) X-Powered-By: PHP/5.3.3 X-Pingback: [http://www.communityadvocate.com/xmlrpc.php](http://www.communityadvocate.com/xmlrpc.php) Connection: close Transfer-Encoding: chunked Content-Type: text/html; charset=UTF-8 http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> My url is [http://www.communityadvocate.com](http://www.communityadvocate.com/)</code> and here's the screenshot from Goolge webmater http://screencast.com/t/FoWvqRRtmoEQ How can i fix that? Thank you
Technical SEO | | Vmezoz0 -
Does 301 redirect cause penalty
Good Morning, I am considering doing a 301 (permanent) re-direct of roughly 100 domains, split between my 3 main e-commerce sites. Would taking an action like this put any of the 100 domains or any of the 3 recipient domains at risk of violating G's guidelines? Thanks...
Technical SEO | | Prime851 -
302 redirects help
Hello, I have a Magento ecommerce store and my latest seomoz crawl report shows over 10,000 302 redirects. An example is this below https://jsshirts.com.au/wishlist/index/add/product/160/ which is being redirected to http://jsshirts.com.au/enable-cookies Can anyone please help me with a solution to help with this problem. Many thanks
Technical SEO | | mullsey0 -
Is the Sandbox Real? Need Help!
To start, I'm very new at this so I've likely made a ton of mistakes but here is the breakdown of what's happened/what's been done to my site. I own a wedding photography company which was based in Portland, we decided about six months prior that we wanted to relocate to San Diego. It was too soon to optimize our website for our new town of San Diego so I created a brand new site. It was born around June 2011. It looks just like the old site but all the content is different (different titles, re-uploaded images, text, etc was optimized for San Diego). What may be my pitfall is I imported our blog posts from the old site to the new site and we continued to keep both blogs live (writing the post in one, importing to the other). San Diego site: http://continuumweddings.com Old Site (now optimized for LA): http://continuumphotography.com From there I began link building. I signed up for the SEO Scheduler and began making the changes suggested there. It told me to sign up for Linxboss, and I did it. Other than that, my links have been build naturally and I have quite a few of them, definitely enough to compete with my top competitors. At one point I was #3 for "San Diego Wedding Photographer" and I stayed there for a couple weeks. Then I began to drop. Now I'm somewhere on page 10. I've read a lot of articles on here and I know I have a lot of things potentially hurting me. Site age, Duplicate content, etc. I'm just not sure why I dropped (still rank on 1st page in Yahoo & Bing) and what I should do about it. I tend to get overwhelmed and every post I read seems to talk about something new I may have done wrong. I'm willing to put in the time to fix this; I just need to know where my time is best spent.
Technical SEO | | mrsmelmitch0