We have a domain alias.com , which is a CNAME to domain.com .
When we navigate to it (it's a Wordpress site) we get unexpected redirects.
E.g. https://alias.com/ => redirected to https://originaldomain.com/en/
Even with malformed paths if it's a different page than the home: e.g. https://alias.com/contact => redirected to https://alias.comcontact
(the slash from /contact got removed magically!).
If we visit a page with the language in the path , like /en/contact
, it works only with the original domain. With the alias domain it gives 404 error (by Wordpress not the web server , since we see a WP page with our theme showing the 404 error , not the default web server's 404 page) .
We verified the redirects are by WordPress not the web server , since the response headers have a "X-Redirect-By: Wordpress"
.
The funny thing is: the www. works well. i.e. https://www.originaldomain.com/contact
correctly loads the page. It's a CNAME like alias.com , so we expected alias.com to work the same.
Now the question is if it's the core WP to blame , or some plugin.
The most likely plugin to blame between the ones we have is TranslatePress , which we really need (cannot disable).
For now we just want to investigate (with custom hooks in functions.php
, logs or something) , to ascertain that WP core is to blame , not a plugin like TranslatePress.
How would we do that?
We have also this in wpconfig
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST']);
define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST']);
and this is our .htaccess
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
<IfModule php8_module>
php_flag display_errors Off
php_value max_execution_time 300
php_value max_input_time 60
php_value max_input_vars 3000
php_value memory_limit 512M
php_value post_max_size 516M
php_value session.gc_maxlifetime 1440
php_value session.save_path "/var/cpanel/php/sessions/ea-php82"
php_value upload_max_filesize 512M
php_flag zlib.output_compression Off
</IfModule>
<IfModule lsapi_module>
php_flag display_errors Off
php_value max_execution_time 300
php_value max_input_time 60
php_value max_input_vars 3000
php_value memory_limit 512M
php_value post_max_size 516M
php_value session.gc_maxlifetime 1440
php_value session.save_path "/var/cpanel/php/sessions/ea-php82"
php_value upload_max_filesize 512M
php_flag zlib.output_compression Off
</IfModule>
# END cPanel-generated php ini directives, do not edit
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php82” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php82___lsphp .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
We have this hook for debugging , in functions.php
add_action('init', function() {
if (is_admin()) return;
header('X-DEBUG-HOST: ' . $_SERVER['HTTP_HOST']);
header('X-DEBUG-HOME: ' . get_home_url());
header('X-DEBUG-SITEURL: ' . get_site_url());
});
When we navigate to https://alias.com
, we get these debug headers
301 Moved Permanently
...
Location: https://originaldomain.com/en/
x-debug-home: https://originaldomain.com/en
x-debug-host: alias.com
x-debug-siteurl: https://originaldomain.com
x-redirect-by: WordPress
then after that redirect the headers are
200 OK
...
x-debug-home: https://originaldomain.com/en
x-debug-host: originaldomain.com
x-debug-siteurl: https://originaldomain.com
x-redirect-by: WordPress
When we navigate to https://alias.com/contact
, we get these debug headers
301 Moved Permanently
...
Location: https://alias.com/contact/
x-debug-home: https://alias.com/
x-debug-host: alias.com
x-debug-siteurl: https://alias.com/
x-redirect-by: WordPress
then after that redirect the headers are
301 Moved Permanently
...
Location: https://alias.comcontact/
x-debug-home: https://alias.com
x-debug-host: alias.com
x-debug-siteurl: https://alias.com
x-redirect-by: WordPress
So at the second redirect , somehow the homeurl
and siteurl
lost a slash.
Thanks
It is due to some idiosyncracy of Translatepress with alias domains. The option "Use subdirectory for the default language" must be disabled for aliases to work properly with the plugin , as they suggested here https://wordpress.org/support/topic/alias-domains-are-unsupported