Subdomain rewrite rule strategy: whitelisting

Here is a quick how-to for a strategy to prevent duplicate content across domains and subdomains of the same site by "whitelisting" discrete domains and redirecting all other requests to the main domain.

Often during a site migration, you add some new subdomains to your virtual ServerAlias configuration. For other reasons, such as supporting "yoursite.ca", "yoursite.com", "yoursite.biz", etc. you add more ServerAlias configurations. To ensure that you don't have issues with duplicate content, you end up creating a bunch of individual rewrite rules such as:

RewriteCond %{HTTP_HOST} ^yoursite\.ca$ [NC]
RewriteRule ^(.*)$ http://yoursite.com$1 [R=301,L]
 
RewriteCond %{HTTP_HOST} ^(new)\.yoursite\.com$ [NC]
RewriteRule ^(.*)$ http://yoursite.com$1 [R=301,L] 

This "blacklist" approach can get messy and reactive, as you add new rules whenever someone tells you that your site is being indexed under another domain that you didn't even think of.

A "whitelist" approach is a bit cleaner, as you specify which domains you want content to be served under, and redirect everything else:

RewriteEngine On
# Allow these subdomains
RewriteCond %{HTTP_HOST} !^(admin|editorial)\.yoursite\.com$ [NC]
# Don't cause a rewrite loop
RewriteCond %{HTTP_HOST} !^yoursite\.com$ [NC]
RewriteRule ^(.*)$ http://yoursite.com$1 [R=301,L]

This works very well for single-domain websites, and you are usually subject to fewer surprises in terms of domains that are pulling up your site content.

If you run a multi-site install where, for example, you're running "yoursite.com" off one subtree and "othersite.com" off another subtree, you will have to make the rewrite conditions above more sophisticated. In such a case, however, the better solution might be to create separate vhost files anyway.

Comments

blog comments powered by Disqus

Contact

604-637-6396
hiATmugo.ca

#414-207 W. Hastings St
Vancouver, BC
Canada


RSS icon Twitter icon

We have been using this team for editing, consulting, support and training services in North America for the last 3 years and we still do. The team has shown their expert knowledge of our systems, and is responsive and dedicated. The services they provide include expert consulting on eZ Publish towards large, high-traffic enterprise customers.

CEO Aleksander Farstad , eZ Systems

I relied on Mugo for the development of two complex web applications, and I was extremely impressed with their accurate estimates, consistent and timely delivery of production code, and commitment. They have the rare blend of business knowledge and deep technical expertise, and they excel at listening to business requirements and translating those requirements into intelligent and reliable software products. They are able to work on all aspects of software solutions -- front end/UI, core code, modules and extensions, application integration, and infrastructure -- and they are extremely capable in all of those areas. I highly recommend Mugo to anyone in need of a competent and dependable technology partner.

Co-Founder Graham Tillotson, Tandem, Chicago

Mugo maintains and develops new features for the Rasmussen Reports website, www.rasmussenreports.com. We are impressed with how efficiently they deliver high quality solutions that exactly fit our needs. The Mugo team understands the complexity of our high traffic website and was able to improve our site's overall performance, as well as its search engine rating. For our site's subscribers, Mugo quickly and efficiently developed many new features for our Premium Section.

The Mugo team is great to work with, and I look forward to a long and productive relationship.

Stephen W Smith, Interim CEO, Rasmussen Reports

If you ask me what is the first thing you think of about the Mugo team, I would say that they listen.

For a customer, the worst thing is to work with a partner that doesn't listen to you. That doesn't understand your points. That simply doesn't listen and try to help you.

Daniel Iribarren, ClearCap

Mugo Web is not another service provider. They are your partners.
One of the things I really like about the Mugo team is that they care about my project and myself. That is why I call them my partners.

Daniel Iribarren, ClearCap

Mugo Web is not just a group of geeks. They are a team of highly knowledgeable technology and business people.
They understand that they are helping you to design solutions to satisfy or solve business problems. And not every developer is able to deliver that. I have worked with more than 10 different let's says production centers and what they delivered to me was geek stuff. Not business solutions.
Mugo Web will help you to use geek stuff to solve business problems.

Daniel Iribarren, ClearCap

It's been a pleasure working with Mugo Web. They are fast, efficient and always helpful. They respond positively to questions and offer great solutions to technical problems.

Susan Wright, Director of Operations, Toronto Arts Council and Foundation

We've been extremely pleased with the work Mugo has done for us. They have been responsive and understanding in dealing with the complexities of our needs.

Wendy Prugh, Program Manager, The Christian Science Monitor

The team members we work with at Mugo have demonstrated a high caliber of competency in the work they do, and it instills great confidence in us to know that we have such quality professionals in our corner. Their consistent delivery has helped us develop a fluid system for enacting change and improvements on our website. We certainly look forward to continuing this relationship!

Wendy Prugh, Program Manager, The Christian Science Monitor

Thank you very much Mugo Web for the website work you've done for our company. You valued & respected our time. You produced quality work. You paid attention to detail and understood the JPLradio concept. Most importantly, we appreciate the good business ethic of our contact person your company provided. For that, I/we thank you.

Troy B. Williams, Founder & Program Director, Just Positive Lyrics Radio.com

We thoroughly enjoy our working relationship with Mugo Web. They are customer-focused, take the time to listen, give good solid advice with our best interests in mind, and have a quick turnaround time. We've had a number of compliments on the new website, which looks goods, functions well, and performs solidly.

Paul O'Sullivan, IT Specialist, New Society Publishers

From our first contact, the team at Mugo has shown an unprecedented level of commitment to our web projects... ending almost 4 years of struggling! In the three months Mugo worked on our new version -- which had stalled with our previous developers -- we have made more progress than ever before. They are fast, precise and thorough, and definitely stand out in the industry!

Sébastien Michel, Director, Frogs-in-NZ

Tweets

  • Looking forward to the next eZ Publish Americas conference call, Friday at 11am PT http://t.co/xJPXRlBX #ezpublish #ezcommunity
    Posted at Wed Feb 22 16:13:12 +0000 2012
  • Celebrating the launch of Canadian book site The 49th Shelf with lead sponsor Amazon.ca; see press release http://t.co/CYUIKUdI #ezpublish
    Posted at Tue Feb 21 15:31:43 +0000 2012
  • eZ Flow edit template more user-friendly on node relation custom attributes; merged pulled request: https://t.co/drgtL7BH #ezpublish
    Posted at Mon Feb 20 15:26:24 +0000 2012
  • @gauthiergarnier Nice! After California we can finally host an eZ event in Canada. It's been lonely. cc @ilukac
    Posted at Fri Feb 17 15:59:13 +0000 2012

Follow Mugo on Twitter