Mobile app version of vmapp.org
Login or Join
Candy875

: .htaccess redirect not working for web alias 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

@Candy875

Posted in: #Apache #Dns #Htaccess #UrlRewriting

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 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 ^(.*)$ example.de/en/ [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?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Candy875

1 Comments

Sorted by latest first Latest Oldest Best

 

@Welton855

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 example.com IN A 001.002.003.004 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 domain.com/* to www.domain.de/en/* RewriteCond %{HTTP_HOST} ^domain.([^.]+).com$ [NC]
RewriteRule (.*) www.%1.de/en/ [R=301,L)

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

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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme