I am just transferring over a WordPress site from Server 1 to Server 2.
The IP address of Server 1 points to example
(A record on DNS server)
The IP address of Server 2 points to www.example
(A record on DNS server)
During the migration, I want to type in www.example
and prevent any redirection - so that I can make sure that it has been set up correctly before
setting the A record for example
to point to Server 2.
There is a .htaccess
file on Server 2, but it isn't redirecting to example
. Just to make sure that it isn't, I renamed it to htaccess.bk
to make sure it doesn't kick in - but no success here.
Any idea what I need to do?
TIA!
I am just transferring over a WordPress site from Server 1 to Server 2.
The IP address of Server 1 points to example
(A record on DNS server)
The IP address of Server 2 points to www.example
(A record on DNS server)
During the migration, I want to type in www.example
and prevent any redirection - so that I can make sure that it has been set up correctly before
setting the A record for example
to point to Server 2.
There is a .htaccess
file on Server 2, but it isn't redirecting to example
. Just to make sure that it isn't, I renamed it to htaccess.bk
to make sure it doesn't kick in - but no success here.
Any idea what I need to do?
TIA!
Share Improve this question edited Oct 31, 2018 at 10:42 fuxia♦ 107k39 gold badges255 silver badges461 bronze badges asked Oct 31, 2018 at 10:19 jagkujagku 1112 bronze badges 1- Can you share your htaccess code here. – Gufran Hasan Commented Oct 31, 2018 at 10:49
2 Answers
Reset to default 1What do you have set in the WordPress admin under Settings -> General and then WordPress Address
and Site Address
? Make sure these are both using the www.example
domain.
If you want to use an htaccess
rule, which will run before WordPress kicks in, there are plenty of answers on StakOverflow such as this one: https://stackoverflow/questions/4916222/htaccess-how-to-force-www-in-a-generic-way
Just put this code in your wp-config.php
file
define( 'WP_HOME', 'your_url' );
define( 'WP_SITEURL', 'your_url' );
In .htaccess file:
Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example [NC]
RewriteRule ^(.*)$ http://www.example/$1 [L,R=301,NC]
Force non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\ [NC]
RewriteRule ^(.*)$ http://example/$1 [L,R=301]
Note: You need just comment out these two lines in .htaccess file by using #
just putting before the line
RewriteEngine on
#RewriteCond %{HTTP_HOST} ^www\.example\ [NC]
#RewriteRule ^(.*)$ http://example/$1 [L,R=301]