.htaccess: .co domains and redirects

A white, rounded square logo with an abstract S-shaped design on a gradient blue and purple background.

When doing multiple htaccess redirects, there is an issue with .co domains conflicting with .com redirects. If you already have a non-www version of your .com domain redirecting into the www version of the .com domain, then any www .co domain redirect into the www .com will cause a failure.

To solve this, you need to put in a $ at the end of a www .co redirect (and sometimes in the non-www too). Otherwise if you leave out the $, you end up creating an infinite loop of redirecting the www.domain.com into www.domain.com (or at least the htaccess thinks you are trying to do that). This crashes all the redirects of the entire site.

The $ signifies end of the expression and stops this from happening as it signifies that you are only trying to redirect .co and not .com. So if you ever end up with a crash situation with multiple similar domain extensions, use the $ at the end of a line. Here is the code to use:

RewriteCond %{HTTP_HOST} ^ domain.co [OR]
RewriteCond %{HTTP_HOST} ^www. domain.co$
RewriteRule ^(.*)$ http://www. domain.com/$1 [L,R=301]

* I have made the $ red to denote the code. Obviously, you do not need to make yours red in your htaccess file (not that you could, if you tried).

Share This
Blog Decorative Background

Join the Sales and Marketing News, receive our last insights, tips and best practices.

Our 7 Guarantees

Keeping 2,000+ Clients Happy Since 2001.

1
You Will Love Your Design We design to please you and your clients
2
Same-Day Support 24-hour turnaround edits during business hours
3
Free Education We provide knowledge to help you expand
4
No Hidden Charges We quote flat-rate projects
5
Own Your Site No strings attached
6
We Create Results SEO, PPC, content + design = clients
7
We Make Life Easier One agency for web, branding and marketing