How to redirect www URLs to non-www
source link: https://www.laravelcode.com/post/how-to-redirect-www-urls-to-non-www
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to redirect www URLs to non-www
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
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]
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK