Doing Website Redirect With NGinx

nGinx is fast becoming one of the most popular web servers around, and it’s no wonder why.,/p>

It’s lightning fast, runs of the tiniest of servers and can handle a tsunami of traffic.,/p>

So what is a website redirect?

It’s simply sends web traffic from one URL to another URL, without the user having to click any links in the middle.

So lets say we want to redirect all traffic going to our old website (lets call it to our new website (lets call its, we would setup a redirect on to send all the traffic automatically to

There are two main types of website redirects (in SEO terms).

There is a permanent redirect (commonly called the 301 redirect). This tells the search engines and more modern web browsers that whenever we see this URL automatically treat it as a different URL

So in out example above, if we put a 301 redirect on, the web browsers and search engines would simply substitute with and basically act as if does not exists anymore.

A temporary or 302 redirect, says to the web browsers and search engines that the link destination may change, so don’t automatically do a substitution.

Let’s says you have a company blog and you set up a redirect to the latest news article.

So something like is a redirect to (2021-07-03 is the date of writing). I want this latest_news to send people to the news article, but when a newer article appears, I want it to redirect tp the newer article instead.

So let’s make these redirect using nGinx, using the example given above.

Some where near the start of your conf file in your /etc/nginx/conf.d/ folder, put the following line:

server {

listen 443 ssl http2;


root /website;

index index.HTML;

ssl_certificate… ;

ssl_certificate_key… ;

# This will create a 302 link

rewrite ^/latest_news$ /news/2021-07-03/article.HTML redirect;

# This will create a 301 link

rewrite ^/latest_news$ /news/2021-07-03/article.HTML permanent;


So you can see that creating nGinx redirect links is pretty simple and the best part is you don’t have to write any code, install any complicated plugins or mess about with databases.

Simply use the power of nGinx to make your life easier.