I've been looking to get my website, whenever a customer would go to .co.united kingdom to become instantly rerouted to .com. In addition to when they visit domain.com to automatically get to www.domain.com

I've the code below during my httpd.conf, it seems to become dealing with domain.com to www.domain.com although not domain.co.uk or www.domain.co.uk to www.domain.com

RewriteEngine on
RewriteBase /      
RewriteCond %{http_host} ^domain.com [NC,OR]
RewriteCond %{http_host} ^domain.co.uk [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,NC]

In case your rewrite rules have been in an htaccess file, this will work. If they're inside a vhost file (or even the Apache httpd.conf itself) attempt to take away the /.

And then try to continually be situation sensitive (get accustomed to since most of languages are situation sensitive it is a good habit to consider):


If inside a .htaccess:

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

If inside a vhost or httpd.conf file:

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

And please use the RewriteLog directive: it allows you to find such problems:

# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On

Let me know whether it works.

May be the title of HTTP_HOST situation-sensitive? The RewriteCond documentation always lists it as being HTTP_HOST, not http_host. The NC flag will not assist with that, because it is applicable towards the string values, not variable names.