admin管理员组文章数量:1130349
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]
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]
本文标签: redirectStop wordpress redirecting www to nonwww
版权声明:本文标题:redirect - Stop wordpress redirecting www to non-www 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749217393a2334389.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论