A constant question that comes to a website owners’ mind is – what to choose between www or non-www URL. In the HTTP URL, the first substring is the domain name. The domain name is generally hosted on the server where the document resides.
A server is not a single physical machine, as several servers can reside on the same system. It is vital to choose one domain as a canonical one. There are two ways to choose a site that is canonical.
One way is to use HTTP 301 redirects, and the other method is to use a link-canonical. You can redirect a non-www URL to a www version of your website with a .htaccess file.
Why Redirect files from non-www to www URLs?
Domains without www or with www are different, but they redirect you to the same website. Having two different URLs for web pages can hurt the ranking of your website. This is why having a uniform URL for all pages is important.
Redirecting a non-www to www URLs can be tricky. But if you know the steps, it won’t take much time. Redirecting to www URLs is beneficial for SEO purposes. By redirection, you will avoid duplicate content on the Google index and prevent split inbound links on the website.
Contents
1. What is the .htaccess file?
.htaccess is a vital file that controls high-level configuration. On the servers that run on Apache, the file allows you to make changes to configurations of the website without having to edit the whole server files. You can access the file in different locations on sever.
Most website owners access it through the hosting account’s file management system or the cPanel system. You can access the file from the FTP client account. But if the file is not visible, check in the hidden file options.
.htaccess files can load custom error pages, force your website to use HTTPS instead of HTTP, and add redirection for URLs.
2. Non-www or WWW – Which to Choose?
If you have to choose between redirecting a www page to non-www or a non-www to www, you need to pick one according to your website requirements. Most sites consider redirecting to the www version from the non-www version for better exposure and security.
- Popular websites like Google, Wiki, and Yahoo redirect their page to the www version.
- Most users also use www when they spell out a website. For example, when you tell someone about a new website, you give the reference of www, right?
Www stands for World Wide Web, which is a part of the domain name itself. Most websites you see on the internet have traditionally made www a part of their domain. Non-tech users use www in the browser address as they relate to it.
But some sites use the non-www version for easy access or to make the website stand out from other websites.
Want to buy a domain name? Use these HostGator domain coupons to get a discount.
3. Redirect Non-www to www URLs using .htaccess
You will need to place the rule in the file .htaccess to redirect a non-www URL to www URL. You can change this via your FTP, control panel, or SSH. Most people use the control panel as it is easier to make changes.
3.1 Steps to edit the .htaccess file from the Control Panel
- Firstly, you will need to visit the file section and open file management.
- Now, navigate to the public HTML directory and right-click on the .htaccess file. Select the edit option here.
- Insert the below-given code under the RewriteEngine on option.
- Now, modify the code with the domain name you have saved, don’t use your domain option. Once you complete the process, save the changes.
- After this step, you will enable the .htaccess rule that will help redirect all non-www URLs to the www version of your site.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
3.2 Redirect on the Apache Server
Most users use the Apache server, and there is a way to redirect a non-www URL to www in an Apache server. For this, you will need to use your hosts’ file manager.
- You can use the FTP program to access the .htaccess txt file. You can rename this file to a .htaccess file if it is in your content management system.
- Edit the file and check if all contents are there in the file. If you can’t find the .htaccess txt file, create another file with the name .htaccess file. Now, you will have to insert the lines written above to modify the code of the file.
- After you complete the process, check your website and try different combinations of your domain name to see if the redirection is working fine.
3.3 Redirect non-www to www using the IIS Windows Server
Before you begin the process, you will have to download the URL rewrite plugin for IIS.
- URL Rewrite tool enables you to create rules to implement URLs that are easier for users to understand.
- Once you install the tool, open the IIS and navigate to the website on which you need to implement a URL rewrite. Select URL Rewrite from the IIS tab.
- Now select the additional rules from the option and add a new rule.
- Select the blank rule or inbound rule or name.
- Then in the pattern enter the * for a new dialog, use the condition input “{HTTP_HOST}”. Check if the input string matches the pattern.
- Enter domain name as “^domain.com$ and select the ignore case.
- In the action, select the redirect option.
- The enter the “{MapProtocol:{HTTPS}}://www.domain.com/{R:1}” inside the redirect URL textbox. Uncheck the box append query string.
- Now, select the redirect type – “Permanent (301)”.
- Now apply add rule for the website from the right side of the panel.
Web config will be updated, after which you will see the code below:
<rewrite>
<rules>
<rule name=”Redirect to www” stopProcessing=”true”>
<match url=”(.*)” />
<conditions trackAllCaptures=”false”>
<add input=”{HTTP_HOST}” pattern=”^domain.com$” />
</conditions>
<action type=”Redirect” url=”{MapProtocol:{HTTPS}}://www.domain.com/{R:1}” />
</rule>
</rules>
</rewrite>
The code is placed inside the “” in the web config option.
You can also redirect from www to non-www using the web config, replace your domain with the domain name using the rule.
#URL rewrite with .htaccess file
Rewrites can be similar to the redirects as they also point out the target to the URL. But some are converted by the web servers while handing the traffic of the website. You think of it as using a pencil and rubber against using sign point to the new name. The most common rewrites force the websites to have URLs.
.htaccess file uses the actual page to redirect your website. It can use 301 and 302 redirects. But the most effective way to redirect a URL is with the .htaccess file. After you complete the process, check your site on the internal pages.
Final Words
Www combination of your domain name should work as expected. It can help improve your site’s performance and boost SEO. So, redirect your non-www URL to www using the different options above to secure your domain.
Looking to buy hosting for your business website? Get a discount by using these free HostGator coupons.
Leave a Reply