How to Redirect Non-WWW URLs to WWW URLs
Website URLs play a crucial role in creating an optimal user experience and search engine optimization (SEO). A non-www URL and a www URL can have a significant impact on the way search engines perceive your website and how users interact with it. Therefore, it is important to make sure that your website has a consistent URL structure to improve its online visibility and credibility.
In this article, we’ll go over the steps to redirect non-www URLs to www URLs, which is a recommended best practice for SEO.
Read Also :- Use Grammarly Premium Cookies: Tips and Tricks 2023
Why Redirect Non-WWW URLs to WWW URLs?
Search engines treat non-www and www URLs as separate websites, even though they’re on the same domain. For example, if you have a website with a non-www URL, like http://example.com, and a www URL, like http://www.example.com, search engines will see these as two different websites. This can cause confusion for both users and search engines, and can negatively impact your SEO efforts.
Having a consistent URL structure can also make it easier for users to remember your website URL, which can improve engagement and user experience.
Improved Search Engine Optimization (SEO): Search engines view non-WWW and WWW URLs as separate entities, which can result in duplicate content and split link equity. By redirecting non-WWW to WWW URLs, you ensure that all link equity and authority is passed to a single version of your website’s URL, which can help to improve your website’s search engine rankings.
Consistent URL Structure: By having a single, consistent URL structure, you ensure that users and search engines can easily access your website, without encountering any broken links or 404 errors. This can help to improve your website’s user experience, and also positively impact your search engine rankings.
How to Redirect Non-WWW URLs to WWW URLs
There are several methods for redirecting non-www URLs to www URLs, and the process depends on the type of web server your website is hosted on. In this article, we’ll go over the most common methods for redirecting non-www URLs to www URLs.
Apache Web Server
Apache is the most commonly used web server software, and it’s used by a large number of websites. If your website is hosted on an Apache web server, you can redirect non-www URLs to www URLs by adding the following code to your
htaccess
file:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Nginx Web Server
Nginx is another popular web server software, and it’s used by a growing number of websites. If your website is hosted on an Nginx web server, you can redirect non-www URLs to www URLs by adding the following code to your Nginx configuration file:
server {
listen 80;
server_name example.com;
return 301 $scheme://www.example.com$request_uri;
}
IIS Web Server:-
IIS is a web server software used by some Windows-based websites. If your website is hosted on an IIS web server, you can redirect non-www URLs to www URLs by using a URL Rewrite rule. Here’s how:
- Open IIS Manager
- Click on the website you want to redirect
- In the Features View, double-click on URL Rewrite
- Click Add Rules, then choose Blank Rule
- In the Name field, enter a name for the rule
- In the Pattern field, enter
(.*)
- In the Conditions field, add a new condition and choose {HTTP_HOST} as the input variable. Set the value to
^example\.com$
- In the Action field, set the Action type to Redirect and the Redirect URL to
http://www.example.com/{R:1}
- Click OK to save the rule
Server-side Programming Languages
If your website is powered by a server-side programming language, such as PHP or ASP.NET, you can redirect non-WWW to WWW URLs by adding a redirect code in your website’s source code. Here are examples of how to do this in PHP and ASP.NET:
// PHP
<?php
if ($_SERVER['HTTP_HOST'] == 'example.com') {
header('Location: http://www.example.com'.$_SERVER['REQUEST_URI']);
exit;
}
What is the difference between non-WWW URLs and WWW URLs?
WWW URLs and non-WWW URLs refer to the same website, but with a different prefix. WWW URLs start with “www” (World Wide Web), while non-WWW URLs do not. Both types of URLs can be used to access the same website, but some websites may redirect you to one version or the other.
Can I access a website with either a WWW or non-WWW URL?
No, there is no difference in terms of website functionality between WWW and non-WWW URLs. Both types of URLs will take you to the same website and provide the same content and functionality.