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
-
3 word brand name + SEO. Will I be losing out on organic searches with spaces?
Hello, Starting a new website and the company name has three words. We've made the decision for the brand guide that we will not have spaces when the name is included in copy. Are we going to have difficulties ranking for both instances? Thanks
White Hat / Black Hat SEO | | jessicarechkemmer0 -
Subdomain and Domain Linking Strategy
Here is my question for SEO. We are a mug printing company and we have a website specifically for bulk orders hosted at our main link (example.com). For the purposes of this example we will assume that we only print mugs for bands. Eg. orders for 100 mugs at a time for a band. We have had a need to create stores for bands so that they can then pass a link to their fans to purchase mugs. Our main website deals specifically with bulk orders only with customer provided logos, so extending this workflow to our main domain takes quite a bit of development time. Because of this, we purchased a service that allows us to create stores under the new domain stores.example.com. The root domain is the same as our main domain but there is “stores” in front of the domain. A band’s website that we would create would then look something like : stores.example.com/band1_merchandise These links are going to be spread by the band all over the web, and it is in my hope to be able to take advantage of this. Ideally stores.example.com/band1_merchandise being spread around will also give us a boost to www.example.com My question is how can we benefit the most from bands sharing the subdomain link such that our main website will be able to see an SEO benefit.
White Hat / Black Hat SEO | | masonwong0 -
Restructuring URLS - unsure if this falls on the spammy side of paths.
Hi all, I'm restructuring a site that has been built with no real structure. It's moving over to HTTPS and having a full new development so it's a good time to tackle it all together. It's a snowboard site and at the moment the courses, camps ect are all just as pages like: examplesnowboarding.com/off-piste-backcountry/ I'm wanting to tighten the structure so it gives more meaning to the pages and so I can style them selectively and make it easier for the client to manage but I'm worried repeating the word snowboard too often will look spammy. I'm wanting to do the following: URL - examplesnowboarding.com/snowboard-courses/splitboard-backcountry-intro/
White Hat / Black Hat SEO | | snowflake74
URL - examplesnowboarding.com/snowboard-camps/technical-performance/
URL - examplesnowboarding.com/snowboard-camps/girls-only/
URL - examplesnowboarding.com/snowboard-lessons/private/
URL - examplesnowboarding.com/snowboard-lessons/group/ The urls are clean and humanly descriptive but it does mean that the "snowboard" keyword is used a lot! The other 2 options I thought of were like so (including snowboard in the page name not path) URL - examplesnowboarding.com/courses/snowboard-splitboard-backcountry-intro/
URL - examplesnowboarding.com/camps/snowboard-technical-performance/
URL - examplesnowboarding.com/camps/snowboard-girls-only/
URL - examplesnowboarding.com/lessons/private-snowboard/
URL - examplesnowboarding.com/lessons/group-snowboard/ or simply removing "snowboard" as "snowboarding" is already in the main url URL - examplesnowboarding.com/courses/splitboard-backcountry-intro/
URL - examplesnowboarding.com/camps/technical-performance/
URL - examplesnowboarding.com/camps/girls-only/
URL - examplesnowboarding.com/lessons/private/
URL - examplesnowboarding.com/lessons/group/ Any thoughts appreciated!1 -
Url suddenlly diappeared from Google search results
Hi, I am facing a big problem wheel Google stop showing a basic url of my site, It was ranked good for more than 35 keywords from 1st to 8st positions, and suddenly I can find it indexed in Google , this is the URL : http://tv1.alarab.com/view-8/مسلسلات-عربية Thnaks
White Hat / Black Hat SEO | | alarab.net0 -
Best practice to preserve the link juice to internal pages from expired domain?
This question relates to setting up an expired domain, that already has quality links, including deep links to internal pages. Since the new site structure will be different, what's the best practice to preserve the link juice to these internal pages? Export all the internal pages linked to using majestic Seo/ ahrefs etc, and set these pages previously linked to? Or 301 redirect these pages to home page? I heard there's a Wordpress plugin that 301 redirects all the 404 errors successfully preserving all the potential link juice.
White Hat / Black Hat SEO | | adorninvitations0 -
Dump Penguin Hit Domain
Just wanting to get some feedback from others dealing with Penguin hits on client's websites. We've got one particularly client that has been hit badly because of a high proportion of link toxicity. After running the Cemper Detox Tool we found that only about 25 links are healthy. We're actually thinking of dumping the domain and moving the website to a new domain and starting again with link building (manually grabbing as many of the existing healthy links as possible on the way). Has anyone out there used this strategy? What do you think of the potential of the Sandbox of the new site vs. the Penguin hit on the old site. Do you think the 'drag' of Penguin is higher than the 'drag' of the Sandbox on rankings? Thanks guys, look forward to your insight!
White Hat / Black Hat SEO | | mavster0 -
URL structure: 301 redirect or leave as is?
Hello, My website, www.coloringbookfun.com is very old and authoritative, but the URL structure is terrible. If you check out some of our subcategories such as http://www.coloringbookfun.com/Kung Fu Panda and individual printables such as http://www.coloringbookfun.com/Kung Fu Panda/imagepages/image2.html You can see that they aren't optimized. I am curious to know the pros and cons of fixing the URL structure and 301ing them to the new optimized url. Will 301ing lose authority and backlinks for the sites pages? Does optimizing the url structure outweigh losing the authority/backlinks?
White Hat / Black Hat SEO | | WebServiceConsulting.com0 -
How much pain can I expect if I change the URL structure of the site again?
About 3 months ago I implemented a massive URL structure change by 'upgrading' some of the features of our CMS Prior to this URL's for catergorys and products looked something like this http://www.thefurnituremarket.co.uk/proddetail.asp?prod=OX09 I made a few changes but din't implement it fully as I felt it would be better to do it instages as the site was getting indexed more thouroughly. HOWEVER... We have just hit the first page for some key SERP's and I am wary to rock the boat again by changing the URL structures again and all the sitemaps. How much pain do you think we could feel if i went ahead and optimised the URL's fully? and What would you do? 🙂
White Hat / Black Hat SEO | | robertrRSwalters0