/
Pack Hosting Panel

Configuring redirects

How do I configure redirects at Hipex?


If you, for example, want to move content or product categories, it is often useful to set redirects. This keeps the old URL, which is usually already indexed by Google, alive.

In this article we explain how to set SEO redirects in Nginx. We assume you are familiar with the here described location and folder structure of the Nginx configurations. Remember that after adjusting the Nginx configuration to reload it using the nginx-reload command.

Types of redirects

concerning redirects, we distinguish two types: internal and external redirects.

Internal redirects

We use internal redirects to redirect traffic internally to another location. The end user has no notice of this.

Below an example of an internal redirect is shown:

if (!-f $request_filename) {
	rewrite ^/static/?(.*)$ /static.php?resource=$1 last;
}

External redirects

As opposed to internal redirects, external redirects are noticable to the user. The purpose of external redirects is to redirect a user to another physical link

Two kinds of external redirects exist:

  • permanent => 301 redirect
  • redirect => 302 redirect

From a SEO point of view it is always recommended to use 301 redirects. In this article you read more about SEO improving redirects.

An example of an external redirect:

# 301 redirect:
rewrite ^/static/?(.*)$ https://otherdomain.nl/$1 permanent;

# 302 redirect:
rewrite ^/static/?(.*)$ https://otherdomain.nl/$1 redirect;

Rewrites Nginx map

If many redirects are configured we recommend using the map module. As here described, this configuration is placed in the scope-http map. In this example we populate the $redirect_uri variable with the URL we want to redirect to.

map $request_uri $redirect_uri {
    trousers/green   /green-trousers;
	sweaters/purple    /purple-sweaters;
}

Next we assure the redirects are correctly executed using the $redirect_uri variable. To do this we create the configuration file ~/domains/<domain>/var/etc/redirect.nginx.conf. Then we add the following configuration to the file:

if ($redirect_uri) {
    return 301 $redirect_uri;
}

Finally, after finishing making adjustments, reload you nginx configuraton using the nginx-reload command.