301 domain name URL variants for canonicalization question in htaccess?
-
#1
RewriteCond %{HTTP_HOST} ^xyz.com [NC]
RewriteRule ^(.*)$ http://www.xyz.com/$1 [L,R=301]
What I want to do here is to redirect URLs that have omitted the “www.” prefix to the full “www.xyz.com” home page URL. That means the home page URL http://xyz.com will not resolve on its own, but instead will redirect to http://www.xyz.com (without trailing slash).
#2
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(default|index).(html|php|htm)\ HTTP/ [NC]
RewriteRule ^(([^/]+/)*)(default|main|index).(html|php|htm)$ http://www.xyz.com/$1 [L,R=301]
What I want to do here is to ensure that any home page URL that includes several versions of explicit page name references, such as default.htm or index.html, will be redirected to the canonical home page URL, http://www.xyz.com (without trailing slash).
Are the rewrite rules correct? Thanks in advance!
-
I've tested both and the logic looks fine.
However, as always with .htaccess changes, I'd recommend testing to verify this has been set up properly once you roll these out (easy enough with a quick ping / page load).
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
-
Backlink Question
I have a backlink on a very popular sports news site PR5 this is a sitewide link. The link is near the top on righthand side. As you scroll down, the page keeps loading more and more information. According to my Google webmaster tools the link is on the site over 21,400 pages. As the stories being submitted are new most of the pages have no PR however there are around 30-40 categories that have PR ranging from 0-4. According to my AHREFS account on a daily basis it picks up between 100-200 new links with on average around 10-20 being lost as the stories are being removed. Would anyone advise I just ask for my link to be on the category pages only or should I leave it as it is? Many Thanks in Advance for any Feedback.
White Hat / Black Hat SEO | | Palmbourne0 -
Change domains and start over?
We have a fairly new client who has taken part in many questionable SEO technique over the past few years (mainly buying links and directory web pages). In an effort to fix this they hired three separate SEO’s – we are the fourth. Over the past 3 months we have spent lots of time following best practice techniques to clean up and improve their rankings (including link removal requests but not yet disavow), and after some initially positive results, things are looking down again. Given Google’s apparent rolling algorithm updates and the mess we have found, we are wondering if the best option is to change domains and start over (downside is that they are in a highly competitive industry)? My other question pertains to a domain change and if we were to change from a plural to a singular, would that be enough for Google? (e.g from www.domains.com to www.domain.com). The idea is that we start the link building process again – but keep their brand intact. Really appreciate any feedback.
White Hat / Black Hat SEO | | E2E0 -
Partial Manual penalty to a URL
Hi Mozers, I have a website which has got a partial manual penalty on a specific url. That url is of no use to the website now and is going to be taken off in 3 months time as the website is going to be completely redesigned. Till then I dont wont to live with the partial manual penalty for this url. I have few things in mind to tackle this: 1. take out the url from the website now (as the new redesign will take 3 months) 2. take out internal links pointing to this url in question 3. file for reconsideration with google stating we have taken off the url and have not generated any backlinks and the backlinks are organic. (no backlinking activity has been done on this website or the url) Please let me know if this works or i will have to get the backlinks removed then the disavow then the reconsideration. Looking forward for ur response 🙂
White Hat / Black Hat SEO | | HiteshBharucha0 -
Redirecting an image url to a more SEO friendly image url
We are currently trying to find the best way of making the images on one of our sites more SEO friendly, the easiest way for us would be to redirect the image URL to a more SEO friendly image URL. For example: http://www.website.com/default/cache/file/F8325DA-0A9A-437F-B5D0A4255A066261_medium.jpg redirects to http://www.website.com/default/cache/file/spiral-staircase.jpg Would Google frown upon this as it's saying the image is one thing and then points the user somewhere else?
White Hat / Black Hat SEO | | RedAntSolutions0 -
Moving from www.domain.net to domain.com?
We're thinking about moving our domain from www.domain.net to domain.com as we just acquired the dot com domain. www.domain.net receives roughly 20million pageviews per month and gets about 90% of it's traffic from search engines. What is best to do in this situation? Should we start using .com instead of .net? 301 redirecting traffic to the .com from .net? Should we drop the www in front?
White Hat / Black Hat SEO | | mschianoyo0 -
Google Sitemaps & punishment for bad URLS?
Hoping y'all have some input here. This is along story, but I'll boil it down: Site X bought the url of Site Y. 301 redirects were added to direct traffic (and help transfer linkjuice) from urls in Site X to relevant urls in Site Y, but 2 days before a "change of address" notice was submitted in Google Webmaster Tools, an auto-generating sitemap somehow applied urls from Site Y to the sitemap of Site X, so essentially the sitemap contained urls that were not the url of Site X. Is there any documentation out there that Google would punish Site X for having essentially unrelated urls in its sitemap by downgrading organic search rankings because it may view that mistake as black hat (or otherwise evil) tactics? I suspect this because the site continues to rank well organically in Yahoo & Bing, yet is nonexistent on Google suddenly. Thoughts?
White Hat / Black Hat SEO | | RUNNERagency0 -
Adding Domain Names
Hi all, I am pretty new to SEO but i wanted to check out an idea with you guys, I have a business that is called Totaldriveways and the URL is www.totaldrivewaysne.co.uk Although Driveways is a big part of what we do, we are also heavily involved in other services to do with landscaping. The idea ive got is to brand each service with the "Total" for eample Total Driveways is a reconisgened name in my area and i would like to expand that into Total Patios Total Artificial Grass Total Driveway cleaning so each page and service come under a similar brand, my question is is it worth buying these domains also and directing them at the specific pages that they are relevant to, these domains are obviously keyword rich and am guessing will create extra traffic, but will i be penalised at all by google etc. I know this is probably simple stuff to alot of you's but i have no idea Thanks John
White Hat / Black Hat SEO | | totaldriveways0 -
Possibly a dumb question - 301 from a banned domain to new domain with NEW content
I was wondering if banned domains pass any page rank, link love, etc. My domain got banned and I AM working to get it unbanned, but in the mean time, would buying a new domain, and creating NEW content that DOES adhere to the google quality guidelines, help at all? Would this force an 'auto-evaluation' or 're-evaluation' of the site by google? or would the new domain simply have ZERO effect from the 301 unless that old domain got into google's good graces again.
White Hat / Black Hat SEO | | ilyaelbert0