How can I redirect my website to a non-www version and also make the non-www version the default version.
This is what I want:
And this is what is currently appearing on my site:
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityHow can I redirect my website to a non-www version and also make the non-www version the default version.
This is what I want:
And this is what is currently appearing on my site:
This process can be broken into 2 steps:
.htaccess
for RedirectionFirst, you should redirect any traffic from www to non-www version of your website, by using a simple rewrite rule:
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
This works for any website regardless of the domain, and covers both HTTP and HTTPS.
If you are not using any SEO plugin, I suggest you add a line for search engines, to tell them which one of the protocols is the main. This can be done by using a code like this:
add_action( 'wp_head', 'add_my_canonical' );
function add_my_canonical(){
echo '<link rel="canonical" href="'.site_url().'" />'
}