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
-
Ranking for non-existing content which is 301 redirected
Hey there, In the beginning of this year I've made complete site migration from Dutch language to English. All the old Dutch URL's were 301 redirected to the English versions. I naturally lost rankings for all Dutch keywords during the next month. On the website there is no Dutch content anymore. But what happened now is that five months later the website started to rank for the Dutch keywords again. The page snippets in SERP are in English but the URL's shown are in Dutch (ending with .nl) and whenever a user clicks on the snippet he/she gets 301 to the correct English version. Any ideas what could be the reason for re-ranking of non-existing pages which gets 301 in SERP?
Technical SEO | | benesmartin0 -
Can new content be added to a url which has a 301 redirect?
I am working on a site which is currently being redesigned. The home page currently ranks highly for relevant search terms, although on the new site the content on this page will be removed. The solution I was considering, to preserve rankings, was to move the content on the home page to a new url, and use a 301 redirect to help preserve rankings for that particular page. The question I have therefore, is am I able to add new content to the home page, and have this page freshly indexed accordingly? Any thoughts or suggestions would be most welcome. Thanks, Matt.
Technical SEO | | MatthewA0 -
301 Redirect Best Practices
Hi SEOs, Question about ranking/redirects. If I have a particular page that is already ranking for a couple KWs in top SERPs, but know there are higher volume KWs I can optimize for should I just leave it as is or change the URL key and redirect for the time being until Google re-indexes. Example:
Technical SEO | | IceIcebaby
current URL: www.example.com/action/best-movies
new URL: www.example.com/action/best-action-movies
(the current would be ranking for "best action moves" whereas the new would include the actual "best action movies" KW) Let me know if I can clarify, thank you!0 -
After I 301 redirect duplicate pages to my rel=canonical page, do I need to add any tags or code to the non canonical pages?
I have many duplicate pages. Some pages have 2-3 duplicates. Most of which have Uppercase and Lowercase paths (generated by Microsoft IIS). Does this implementation of 301 and rel=canonical suffice? Or is there more I could do to optimize the passing of duplicate page link juice to the canonical. THANK YOU!
Technical SEO | | PFTools0 -
Switching from a .org to .io (301 domain redirect)
I'm considering switching my main site from a .org to .io address; the .org is an exact match domain which helped to kickstart it a few years ago and now has about 50% repeat visitors, but was thrown off the Apple affiliation program for trademark infringement. I've found and purchased a nice (non-infringing) .io domain, and I've read the advice here on how to properly 301 the old domain; but my question is - does it matter that it's .io? Is this going to significantly hurt my rankings, even when everything has been 301'd properly? Another thought I had is that I may actually come out better off in the long run, what with Google penalties being applied to exact match domains. Is this a ranking suicide? If so, I'm tempted to leave it as is; even without the affiliation, it's making a good amount every month in ad fees that I don't want to disrupt. Thanks all!
Technical SEO | | w0lfiesmithUK0 -
Setup 301 Redirects
I have been asked to transfer a clients old domain over to a new domain with a new site. All of the inbound links basically go to the homepage, and the few links that dont go to the homepage on the old site, might as well be redirected to the homepage on the new site. I'm wondering is there a "catch all" sort of redirect such as www.oldsite.com/* redirects to newsite.com. So any redirects we havent set up will automatically go to the new site homepage? And secondly, whats the easiest way to the redirects up? Can I just add it as a parked domain or addon domain in cpanel, and do the redirects in there? Or does it needs its own hosting for the old domain with its own htaccess file? Any help appreciated! 🙂
Technical SEO | | timscullin0 -
301 redirect .htaccess problem
Can anyone explain to me why this doesn't work? Redirect 301 /category/diamond-pendants/nstart/1/start/(.*) http://www.povada.com/category/pendants/nstart/1/start/$1 Im trying to replace everything after /start/ and insert it into the new url. Thanks in advance.
Technical SEO | | 13375auc30 -
Minisites - 301 Redirect or Links to Main site
Not sure whether this is considered black hat or not but I know it is done and I would like to know which is the most effectrive method. If you were to acquire multiple sites in the same niche to your main site (either by buying existing sites or perhaps registering expired domains) which already had strong aged backlinks, is it better to either: a) 301 the new domain to the main site (or a subpage perhaps) b) create 'minisites' on the new domains (trying to mirror the URL structure of the previous incarnation if possible to scoop up and remaining inbound backlink juice, on seperate IPs to the main site as well) and then place several links to the main site & subpages. Would the decay of link juice through 301's mean you lose benefit that way or is it the same as a normal link? Would the 301 method mean any IBL's into URL's other than the homepage be lost? The homepage of the minisite will likely have 4 or 5 internal links so will this dilure the effect of the links to the main site? Thanks in advance!
Technical SEO | | OzDave0