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

Linux / UNIX: Encrypt Backup Tape Using Tar & OpenSSL

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

Linux Install Google Chrome Browser [ Ubuntu, Suse, Debian, Fedora ]

How do I install Google Chrome browser under Linux operating systems? How do I install...

Changing Default SSH port From 22

nano /etc/ssh/sshd_configLook for#Port 22Change "22" to the port you wish to use.CTRL + X, Save...

Yum issues with low memory plans (Resolution)

If you are getting yum errors on our 128 or 192 yearly plans with the CentOS/Fedora distro then...

Bash Shell Generate Random Numbers

How do I create or generate random numbers (sequence of numbers that lack any pattern), under...