$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>redirect - Stop wordpress redirecting www to non-www|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

redirect - Stop wordpress redirecting www to non-www

matteradmin8PV0评论

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
Add a comment  | 

2 Answers 2

Reset to default 1

What 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]
Post a comment

comment list (0)

  1. No comments so far