Web Design. Web Development. Web Hosting.
0 items

using htaccess to force either www or not in your url

Need some help? We are here for you!

We have a very friendly service - Come and chat to us and let us know what you need, we work for an hourly fee and can also provide you a no obligation quote and begin work immediately in most cases. Click "Request Support" or use our Live Chat.

Request support

One of the biggest mistakes when setting up a website is not deciding whether or not to use www in the URL to your website, almost all servers are set-up to automatically link the www. subdomain to your main domain because www. is widely used by many web masters. This presents a problem though because by default any website that is set-up is now duplicated on both www.mysite.com and mysite.com.

This presents a big problem because people who navigate directly to your site may do either and if the site loads for both URLs without a redirect that user can browse the site, share it on social media, link to it from their websites and etc. Google then picks up these two URLs and indexes them causing duplicate content which will harm your Google rankings considerably over time.

The first thing you need to do is decide whether or not you are going to use www.mysite.com or mysite.com, there are pro’s and con’s for both practices, we would recommend not using www. as your domain will look cleaner in the address bar, especially if you decided to go https in the future, a visitor will see your domain name instantly after the green https reassuring them that they are on the right domain.

However this is completely up to you and from experiments performed by many SEO experts Google does not seem to prefer either method.

 

Force your site to use www

All you need to do is add the following code into your htaccess file:

RewriteEngine On
# Force www
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1

 

Force your site to remove www

All you need to do is add the following code into your htaccess file:

RewriteEngine On
# Force NO www
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

 

0 0 votes
Article Rating
Need some help? We are here for you!

We have a very friendly service - Come and chat to us and let us know what you need, we work for an hourly fee and can also provide you a no obligation quote and begin work immediately in most cases. Click "Request Support" or use our Live Chat.

Request support
Author: Dean WilliamsProfessional PHP Web Developer with expertise in OpenCart Web Development, WordPress Web Development, Bespoke Systems - also a seasoned Linux Server Administrator.


Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments


Share this page..

Let's begin your journey...

Get in touch us now to begin your journey to having a beautifully crafted mobile responsive website. If you're still unsure what we could do for you then take a look at our why us page which includes reviews, or take a look at our portfolio.

We can work on improving existing websites or craft a new stylish website making your business stand out.

You could always catch us by email, telephone, Skype or live chat to us below.


    0
    Would love your thoughts, please comment.x
    ()
    x