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
-
Link Building - Blogger Outreach - Need Help!
I am looking forward to create a solid link building campaign for my affiliate blog. But, what I want is completely GENUINE and effective link building. Could anyone please suggest what strategies should I opt for. I am planning to get Guest Blogging done? But, is it effective anymore. I have read so much about companies posting on Private networks.
Technical SEO | | scott_eastman
Are there actually companies out there that actually outreach blogs? it would be helpful if somebody could refer based upon personal experience. Much Appreciated!1 -
Is there anyway to automatically find complete urls for 301 redirects?
Hello all, I'm working on a large site that is being prepared for a migration. After scraping on screaming frog, WMT, and deepcrawl, and deduping I have a list of 404 pages that need redirected. Many of these URLs are just incomplete URLs. For example the incomplete URL would be: "https://moz.com/beginners-guide-to" when it should be "https://moz.com/beginners-guide-to-seo" I have been finding the correct page manually searching google. With hundreds more to go, I am looking for a way the would be a little less laborious. Thanks! https://moz.com/beginners-guide-to-seo
Technical SEO | | AdamBohr0 -
Need 301 Advice with a Recovered URL from a Domain Typosquatter
I am new to a SMB and someone bought the plural version of our domain back in 2005 and has yet to let it expire. The domain was just renewed for another year so we finally decided to contact a lawyer and go through the domain name dispute process. This seems like a pretty cut an dry case and the lawyer is very confident that we'll have the domain within 30-40 days. Currently the plural version domain 303s to spammy web pages, shows shady ads and is just a malicious looking page in general. I am not savvy enough to know the exact complexities of what's happening on the backend but it's spammy. Knowing the history of the plural version domain, how would you treat it after we acquire it? Obviously, I wouldn't want to put our site in jeopardy by 301ing the plural version of our URL to our current healthy site but at the same time many customers might go to that domain by accident so eventually I'd like to 301 it. If it's any help, the plural version has a robots.txt that prevent G from crawling it..thank you in advance for your guidance!
Technical SEO | | ssimarketing0 -
301 Redirect with ASP (not .NET)
I'm looking to redirect non www to www and also .co.uk to .com. http://www.xxxxx.com is the intended target. http://xxxxx.com & http://www.xxxxx.co.uk & http://xxxxx.co.uk to redirect. I managed to do some of this but if I come through to a service page /services/cars.asp it redirects to the homepage. All I have so far is this code: <% If InStr(Request.ServerVariables("SERVER_NAME"),"www") = 0 ThenResponse.write "http://www." & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("URL") & "?" & Request.ServerVariables("QUERY_STRING")Response.EndEnd if %> What am I missing?
Technical SEO | | Hughescov0 -
301 Redirect From Dynamic Page To Static
I want to 301 redirect all "id" and "type" numbers from my page dynamic.php page (I have thousands of IDs and thousands of Types) all to a single URL. So for example the following.... www.mysite.com/dynamic.php?id=1&type=5 www.mysite.com/dynamic.php?id=2&type=5 www.mysite.com/dynamic.php?id=3&type=5 www.mysite.com/dynamic.php?id=1&type=6 www.mysite.com/dynamic.php?id=2&type=6 www.mysite.com/dynamic.php?id=3&type=6 ...would all be sent to: www.mysite.com/page.html How can this be done without doing a redirect for each ID/Type?
Technical SEO | | TheDude1 -
Redirects 301
Hello, I need to reedirect a URL of a page that I have in my site (http://digitaldiscovery.com.pt/servicos-de-marketing-digital/publicidade-online/) to a new URL with SEO porpuses. Whats the best way to this? I use Wordpress btw. Tks in advance! PP
Technical SEO | | PedroM0 -
301 redirect domain to page on another domain
Hi, If I wanted to do a 301 permanent redirect on a domain to a page on another domain will this cause any problems? Lets say I have 4 domains (all indexed with content), I decide to create a new domain with 4 pages, one for each domain. I copy the content from the old domains to the relevant page on the new domain and set it live. At the same time as setting the new site live I do a 301 permanent redirect on the 4 domains to the relevant pages on the new domain. What happens if Google indexes the new site before visiting the redirected domains, could this cause a duplicate content penalty? Cheers
Technical SEO | | activitysuper0 -
I need some HTACCESS help (Magento)
Hi Guys, I need some help on this htaccess issue in Magneto. So here is what I am trying to do: I wanted to change mysite.com/index.php/etc to mysite.com/etc so I turned on the web friend URLS. That did that, BUT there are still two versions of every page on the site. www.mysite.com/etc and mysite.com/index.php/etc So that isn't good for SEO. So then I applied a 301 matching redirect, RedirectMatch 301 /index.php/(.*) http://www.mysite.com/$1 That solved that problem. But now I am not able to log into the admin. It is mysite.com/index.php/pg45admin. It should redirect to mysite.com/pg45admin but the page just hangs.... It goes into a continuous loop. I tired using the custom URL and then the site crashed and I had to redo it. So what do I need to do for this to work?
Technical SEO | | netviper0