Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to Redirect WWW URLs to Non-WWW in WordPress

When you create a website or blog, it is very important that you optimize your site for the search engine. One of the things that you should do to improve your SEO is to have proper 301 redirects to your base Domain. What I mean to say is that you must choose between using WWW subdomain or not using it for your base domain.

Traditionally, most people prefer using WWW subdomain as their base or root domain. In fact, Bloggersignal uses the www subdomain.

However, if you don’t want to use the WWW subdomain then it is important that you create proper redirects to your non-WWW base domain.

What Happens in Case of No Proper Redirection?

Here are some issues that you may face when there are no proper redirects to your base domain.

  • Search engines will see your non-www domain and www domain as separate entities.
  • Since the same content (or 404 error in some cases) is shown on both the pages, search engines may see it as the duplicate content.
  • No proper redirection to your base domain may confuse search engines.
  • Can also disrupt the link flow when websites link to your www domain when in fact you prefer non-www domain.

So without further ado, here is how to redirect WWW URLs to non-WWW in WordPress.

Also read: how to stop WordPress from guessing Urls and redirecting users

Redirect WWW URLs to Non-WWW from cPanel

Most web hosts provide cPanel to easily manage your website. Fortunately, you can use the same cPanel to redirect WWW URLs to non-WWW URLs.

To start off, log into your cPanel, find the Domains section then click on the link “Redirects.”

redirect-www-to-non-www-cpanel-redirects

This open the Redirect page. Here, configure the settings as shown below.

  1. Select the option “Permanent (301)” from the drop-down menu next to “Type.”
  2. Select your domain name from the drop-down menu in the next line.
  3. Enter your domain name without the www subdomain the next line. Don’t forget to add the http:// prefix.
  4. Select the radio button “Only redirect with www.”

redirect-www-to-non-www-redirect-non-www-domain

Now, click on the button “Add” and you are good to go. From this point forward, every time a visitor or search engine tries to access www.example.com, they will be redirected to example.com.

Redirect WWW URLs to Non-WWW Using .htaccess

Note: before modifying the .htaccess file, create a backup of the file so that you can restore it if needed.

It is very easy to redirect WWW URLs to non-WWW URLs using a simple .htaccess rule. In fact, this method is pretty helpful if you don’t have standard backend interface like cPanel.

To start off, log into your website’s FTP account and then open the .htaccess file located in the root directory. If you can’t find the file, make sure that the FTP client is showing hidden files.

redirect-www-to-non-www-open-htaccess-file

Once the file has been opened, copy the below code and paste it on top of the file, save it and reupload it. Don’t forget to replace example.com with your actual domain.

#Redirect WWW URLs to Non-WWW in WordPress
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

That’s all there is to do. From this point forward, your www domain will redirect to non-www domain.

Alternative method: without hard coding the URL

If you look at the above code, you will see that the code is hard coded with your website URL. If you don’t want to hardcode the domain name then use the below code.

#Redirect WWW URLs to Non-WWW in WordPress without hard coding the URL
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Both the code snippets will work the same. But, only use one. Don’t use both at the same time.

Hope that helps and do comment below sharing your thoughts and experiences about using the above methods to redirect WWW URLs to non-WWW URLs in WordPress.

Credits: thanks to Ben from Stackoverflow for the alternate .htaccess code.



This post first appeared on WordPress Tips And Guides - Bloggersignal, please read the originial post: here

Share the post

How to Redirect WWW URLs to Non-WWW in WordPress

×

Subscribe to Wordpress Tips And Guides - Bloggersignal

Get updates delivered right to your inbox!

Thank you for your subscription

×