How to manage server-side redirections

In this article

What are server-side redirections?

Server-side redirections are a method of redirecting a URL that is performed by the web server. When a user tries to access a certain page or URL, the server recognizes the request and redirects the user to the appropriate page or URL.

Is it any different from what I can currently do with a WordPress plugin?

The advantage of using a server-side redirection over a WordPress plugin is that it is faster and more efficient. Since the redirection is handled by the server itself, there is no need for the website to load WordPress or any plugins, which can be resource-intensive and slow down the website’s performance.

We still recommend that you have a WordPress redirection plugin, specially those that are SEO oriented, in which they will create redirection rules when you change one permalink to another.

How to set up a server-side redirection for one website that you are already managing

Go to the Redirections tab on your server.

Redirections

You will find the websites that you have on your server right there. You then click the “+” icon on the website block (at the left of the padlock and the trashcan).

The redirection window will appear:

You can then choose what URL you want to redirect. In this example, we want /servpress to redirect directly to our website https://servpress.net, so we set it up:

And then we click Add redirection:

We try it out, and we see that it works! Now that we have tested it, we want to make it permanent, so we flip the switch and it becomes a 301 redirection. Read more about redirections directly on Google’s documentation.

How to add a domain-wide redirection

To add a redirection that takes all requests to a domain and redirects them to another URL, you have to repeat the aforementioned steps, but when asked about the current URL, you put the URL without any URI, and without the trailing slash.

Here’s an example case: I want to redirect all vultr-test1.servpress.xyz routes to servpress.net — So this is what I do:

It’s important that you notice the lack of the trailing slash. If you put a trailing slash, ServPress will interpret that you just want the root URL to be redirected, instead of the whole domain.

Once added, we can confirm we are doing it correctly by checking the list of redirections:

How to add a domain-wide redirection that also redirects the request

This is a common question so we feel like we have to include it. Considering the previous example, what if when I access vultr-test1.servpress.net/wp-login.php I want it to redirect to servpress.net/wp-login.php?

The redireciton rule from above would take all routes and redirect everything to servpress.net, regardless of the routes. But if you want it to be a 1:1 redirection, there’s extra work to do so the redirection rule respects the URI. The URI, or Universal Resource Identifier, would be the /wp-login.php part in this example.

This time, we’ll add the following redirection rule:

Notice again the lack of the trailing slash on the current URL, and also that we added a {uri} variable to the destination URL.

How to add redirections for a domain without the domain having a website managed by ServPress

In other words, you have a domain you want to act as a redirection, but you don’t have any website on it. You just want it to redirect, or maybe you want to use it as a short domain to redirect some URLs. No problem! We’ve got you covered. Just add it as you would with any other redirection. For instance, in this example, we don’t have the domain vultr-test3.servpress.xyz on our websites list:

No problem! Let’s add it on the Redirections tab:

Now it’s on the list of redirections:

But uh oh, it didn’t respect our https:// prefix!

That’s because you have to go through the TLS certificate installation process, by clicking on the unlocked padlock icon:

In this case, we already had the subdomain DNS pointing to the server, so we can opt for a Free TLS certificate with autorenewal easily. And now, we can see the green padlock right on the list:

If you want to know more about the TLS certificates, click here to follow our guide.

More tricks for your redirection-fu

If you want to learn more cool things that you can do with server redirections, we encourage you to read Caddy’s documentation on the matter.

Do you have more questions?

Join our community today and feel free to ask about ServPress.

We’ll do our best to help you out.

WordPress Cookie Notice by Real Cookie Banner