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

OpenSSH Hide Version Number From Clients

How do I hide ssh number from clients? When I type the following command it displays server...

nginx: Setup SSL Reverse Proxy (Load Balanced SSL Proxy)

everse proxy is a proxy server that is installed in a server network. Typically, reverse proxies...

PHP Increase Upload File Size Limit

Your php installation putting limits on upload file size. The default will restrict you to a max...

PHP Security: Limit Resources Used By Script

How do I control and put limits on php scripts such as maximum execution time of each script and...