When considering to SEO, if you are not redirecting www to non-www or vice-versa, then search engines like Google webmaster, Bing will create multiple URLs of same link.
You can redirect www to non-www URLs by server side language or through web server like apache or NginX server. In this article, we will go through how to redirect www URLs to non-www URLs through apache web server or NginX server.
NginX web server default configuration file stored at /etc/nginx/nginx.conf
. You can put the below code in server key or create a new configuration file in your configuration directory, like /etc/nginx/conf.d/website.conf
and place the following configuration options.
server {
server_name www.website.com;
return 301 $scheme://website.com$request_uri;
}
Apache web server
Apache is widely used in web application. Apache website custom configuration file .htaccess located at root directory of project. All you have to do is add the below code between <IfModule mod_rewrite.c>
and </IfModule>
.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.website.com$ [NC]
RewriteRule ^(.*)$ http://website.com/$1 [R=301,L]
If you have SSL installed for your domain, put https
instead of http
in RewriteRule
Thats it what you have to do. In the next article, we will also discuss how to redirect non-www URLs to www URLs. So if you want your website url with www, then it will be helpful to you.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
How to increase automatic logout time in phpMyAdmin
phpMyAdmin is open-source web based appl...Set Up Angular Project From Scratch
Angular is open-source web application f...Laravel 8 - How to Get IP Address?
In this article, I will share with you h...How to Add New Elements at the Beginning of an Array in JavaScript
Use the unshift() Method You can use...How to get XML sitemap date format in PHP
Sitemap is important file and route for...