I have wordpress in this domain:
http://www.Dummy.com/en
And want to use second domain such this:
http://www.Dummy2.com
for this wordpress.
How can I redirect Dummy2 to Dummy?
This is some codes that I find out but I couldn't understand them:
wp-config.php
define('WP_SITEURL', ((is_ssl() == true) ? 'https://' : 'http://').$_SERVER['HTTP_HOST']);
define('WP_HOME', ((is_ssl() == true) ? 'https://' : 'http://').$_SERVER['HTTP_HOST']);
The best practice is to setup a redirect on a web server side rather than trying to make your website to do so when WordPress doesn't support multiple domains out-of-the-box. Depending on your chosen web server setup there are two answers for you.
1. Apache
You can use the RedirectPermanent directive with a simple VirtualHost, read more here
#Location:/etc/httpd/conf/httpd.conf
<VirtualHost *:80>
ServerName www.Dummy2.com
RedirectPermanent / http://www.Dummy.com/en
</VirtualHost>
If only your Dummy2
website would be configured as a WordPress-based site too then,a ternatively, you can add a redirect rule to .htaccess
inside of your DocumentRoot configured for www.Dummy2.com site.
RewriteEngine On
RewriteRule ^(.*)$ http://www.Dummy.com/en/$1 [R=301,L]
2. IIS
Make sure that you have an URL Rewrite module installed and simply create a new rewrite rule as follows:
<rule name="Dummy2.com" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(.*)?Dummy2.com" />
</conditions>
<action type="Redirect" url="http://www.Dummy.com/en/{R:0}" />
</rule>
It is not a good practice, but:
$host = $_SERVER['HTTP_HOST'];
switch ($host) {
case 'www.Dummy.com/en':
define('WP_HOME', 'http://www.Dummy.com/en/');
break;
case 'www.Dummy2.com':
define('WP_HOME', 'http://www.Dummy2.com/');
break;
default:
define('WP_HOME', 'http://www.Dummy2.com/');
break;
}
define('WP_SITEURL', WP_HOME);