3

I have two domains at one.com: example.com and example.de

I would like to redirect from example.com to example.de/en

I wanted to use an A record so that example.com points to example.de and then use .htaccess to redirect requests coming from example.com to http://example.de/en but one.com did not accept the ip address. The support said it is because the ip points to the same server.

Then I tried a so called "Web Alias". The alias did work but the redirection rule in my .htaccess did not do anything. I suppose it is because the Alias maps one name to another name instead of an ip.

This is the relevant part of my .htaccess file:

RewriteCond %{HTTP_HOST} ^(www.)?example\.com$ [NC]
RewriteRule ^(.*)$ http://example.de/en/$1 [R=301,L]

Is "Web Alias" the same as an ALIAS record? Is it true that a .htaccess condition does not work with an ALIAS in that way?

  • 1
    Terminology does differ a bit, but I think an "Alias" (or "Add-on" or "Parked") domain is the correct thing here. Simply pointing an A record to your server is not going to work, since the server is not going to know to accept requests directed to that host. So, by "work" I assume you mean that you see example.com in the address bar and the content from example.de is served? In this case, the .htaccess directives you've posted should work? (The first dot in the RewriteCond pattern should be escaped, but that is not a show stopper.) – MrWhite Feb 17 '15 at 15:16
  • @w3d Sounds like an answer to me. – closetnoc Feb 17 '15 at 15:22
  • yes, that is what I mean by "work". I will try again as soon as the dns has updated … – gang Feb 17 '15 at 15:29
  • Certainly, if this is something you have only recently set up then you will need to wait for the DNS to propagate. You also have to be wary of testing 301 redirects as they are cached by the browser - so if you get it wrong the first time and the browser caches the wrong response... – MrWhite Feb 17 '15 at 15:35
  • Thanks. I am constantly clearing my browser cache. The strange thing is that www.example.com already points to the content from example.de but the rewrite condition just does not seem to match. when I remove the first line everything gets redirected. – gang Feb 17 '15 at 15:41
1

The issue of one.com not accepting the same IP address for the A record of 2 domains to me suggests the provider has a slightly odd or bespoke setup, and this limitation is in their control panel, and not the capability of their server to manage 2 domains on one IP address. I manage large numbers of domains on single IP addresses without any problems, perhaps the way they have designed their system you may have to register two separate hosting accounts to achieve this? Sometimes it helps to register and manage your domain names with a different provider to your web hosting. Decent domain name providers will give you all the options for DNS records.

Web Aliases, Parked Domains, Add-on Domains, etc do not normally redirect HTTP requests but are simply configurations which identify the server the request needs to be sent to. Say for example if an alias had been setup for example.com, "you can find me at the same address as example.de", and this is normally achieved using a CNAME DNS record.

.htaccess rules process incoming HTTP requests and can redirect them to another URL amongst other capabilities.

Some people really prefer to use CNAME's wherever possible while others tend to avoid them. There are pros and cons for each case, though my preference is to use A records as they offer me greater flexibility.

One solution you could use in this circumstance, might be:

Setup A record pairs (@, www) for both example.com and example.de to point to the IP address of your web server.

example.com      IN A  001.002.003.004
example.de       IN A  001.002.003.004
www.example.com  IN A  001.002.003.004
www.example.de   IN A  001.002.003.004

Use .htaccess rules to ensure all inbound HTTP requests are 301 redirected to the appropriate URL's as required:

# Redirect http://domain.com/* to http://www.domain.de/en/*
RewriteCond %{HTTP_HOST} ^domain.([^.]+).com$ [NC]
RewriteRule (.*) http://www.%1.de/en/$1 [R=301,L)

# Redirect http://www.domain.com/* to http://www.domain.de/en/*
RewriteCond %{HTTP_HOST} ^www.domain.([^.]+).com$ [NC]
RewriteRule (.*) http://www.%1.de/en/$1 [R=301,L)

# Redirect http://domain.de/* to http://www.domain.de/*
RewriteCond %{HTTP_HOST} ^([^.]+).de$ [NC]
RewriteRule (.*) http://www.%1.de/$1 [R=301,L)
  • But on a shared host ("large numbers of domains on single IP address") you are going to have to do more than just create an A record pointing to the server's IP address. – MrWhite May 20 '15 at 22:03
  • For each domain (domain.com, domain.de) you would still need a corresponding hosting account or add-on/parked domain on the shared host, where you would host the .htaccess file with these rules. This combination is all I've ever needed. When creating a hosting account or add-on domain with the shared host they normally automatically update their own configuration and internal DNS to ensure incoming requests are routed to the right hosting account/domain. Obviously this may vary between hosting providers. – richhallstoke May 21 '15 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.