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

Nginx: Custom Error 403 Page Not Working with IP Deny Configuration

I block or deny access based on the host name or IP address of the client visiting website under...

CentOS / Redhat: Install KVM Virtualization Software

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

SUSE Linux Restart / Stop / Start Network Service

Task: Start Network Service # /etc/init.d/network start # /etc/init.d/network start eth0 Task:...

CentOS / Redhat: Create Software RAID 1 Array

RAID devices are virtual devices created from two or more real block devices. Linux supports...

Setting up VPN for CentOS

First, You will need to open up a ticket with our support desk and ask for TUN/TAP to be enabled...