I'm trying to redirect domain.com
to domain.se/en
, but it just won't work. It's like another rewrite or redirect is happening to domain.se/sv
before I get the chance. I've tried multiple VirtualHosts configs and .htaccess
variants without success. domain.com
uses an A record that points to the same IP as domain.se
(main domain) does. I suspect the WordPress plugin Polylang might be rewriting the URL or causing a redirect before I get the chance.
My .htacces
currently looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} .*domain.com.*$
RewriteRule ^(.*)$ http://domain.se/en [L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
and my VirtualHosts config looks like this: (Note that both .no
and .fi
also wrongly redirects to .se/sv
)
NameVirtualHost *:80
<VirtualHost *:80>
ServerName domain.com
ServerAlias www.domain.com
RedirectPermanent / http://domain.se/en
</VirtualHost>
<VirtualHost *:80>
ServerName domain.fi
ServerAlias www.domain.fi
RedirectPermanent / http://domain.se/fi
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin@domain.com
ServerName domain.se
ServerAlias www.domain.se
ServerAlias domain.no
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html>
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
This is what it looks like in Chrome Dev tools Network section when I try to go to domain.com
:
I flushed DNS cache locally and in Chrome before visiting the domain.