Nginx Force (Redirect) WWW.Domain.COM To Domain.COM

I know how to force and redirect www.example.com to example.com under Lighttpd web server. How do I force nginx web server to redirect www.example.com/page/1/2/3 to example.com/page/1/2/3?

You can easily redirect www to nowww domain for SEO and other purposes using the following syntax. Edit nginx.conf file, enter:
# vi /usr/local/nginx/conf/nginx.conf
To force www.theos.in/page.html to theos.in/page.html, enter:

### redirect www to nowww with client code 301 ###
if ($host = 'www.theos.in' ) {
rewrite ^/(.*)$ http://theos.in/$1 permanent;
}
 

Save and close the file. Test and reload nginx webserver, enter:
# /usr/local/nginx/sbin/nginx -s reload
Fire a webbrowser and type the url:
http://www.theos.in/windows-xp/free-fast-public-dns-server-list/
It should be redirected to
http://theos.in/windows-xp/free-fast-public-dns-server-list/

Was this answer helpful?

 Print this Article

Also Read

How to change the root Password using SSH

Changing your Root Password Using SSH This article will show you how to change the root...

yum update Linux Error: Missing Dependency: xen-libs

When I type "yum update" under RHEL 5.x server I get the following error: Error: Missing...

How do I find out System / Server Memory Utilization

free command example Type the free command at shell prompt: $ free $ free -m Output:...

CentOS / Redhat: Install KVM Virtualization Software

Required Packages You must install the following packages: kmod-kvm : kvm kernel module(s)...

Linux / UNIX: Encrypt Backup Tape Using Tar & OpenSSL

  How do I make sure only authorized person access my backups stored on the tape drives...