How to redirect non-www to www in apache and nginx web server

Introduction

In some Cases you want to Redirect  All request that Comes to your Root Website

Configuration

1- Easily you can install APT-Cacher-ng by run Following Command :

				
					server {
    listen       80;
    server_name  packops.dev;
    return       301 http://www.packops.dev$request_uri;
}

server {
    listen       80;
    server_name  www.packops.dev;
    ...
}


				
			
				
					<VirtualHost *:80>
    ServerName packops.com
    Redirect permanent / http://www.packops.dev/
</VirtualHost>

<VirtualHost *:80>
    ServerName www.packops.dev
    # real server configuration
</VirtualHost>
				
			

Conclution

You Can Cache Packages , Speed UP Downloading Packages and Also Not Accessing Your Servers To the Internet By Simply Using APT Cacher-NG

1 thought on “How to redirect non-www to www in apache and nginx web server”

Leave a Comment