Nginx Only, can't make a 301 redirection


I have tested many things like:

    location /meilleur-cable-fibre-optique/ {
        return 301;

That I placed above the location / directive.


if ($request_uri ~* "^/meilleur-cable-fibre-optique/") {
        return 301;

That I have placed inside the location / directive.

But as you can see doesn’t redirect to the homepage. (feel free to remove the link if it doesn’t help).

What should I do? There is no syntax error!

It should be working, no?

Thanks in advance!

Hello @Marcus,

You didn’t say you are using Cloudflare. I don’t use it but maybe you should create a page rule to do the redirection.


Thank for your answer, you think that could be the problem?

I have another redirection located in the location / directive:

        if ($request_uri ~* "^/*)$") {
            return 301$1;

This one is working as you can see: ᐅ Fibre Optique à Saint-Herblain | Test d'éligibilité fibre optique it redirects pages I had broken haha!

I would rather not use cloudflare for the redirection because we are limited with the number of page rules we can have (only 3) and I have to make around 10 other redirections like this one :frowning:

I really don’t understand why this one above works, and not the one in my initial post :confused:

(thanks again for the answer!)

Remove the last slash in location:

location /meilleur-cable-fibre-optique {
    return 301;

Where are you adding that location? I’m asking because you should add it to nginx.conf_whatever and/or nginx.ssl.conf_whatever (you can change whatever by the name you want).

1.- You should do it this way so your conf won’t be overwritten when rebuilding the domain.
2.- If you are forcing https, then you must be sure to include the new location in nginx.ssl.conf_whatever

And remember to reload nginx:

systemctl reload nginx


I removed the last slash in location, and reloaded nginx but it seems that it’s still does nothing!

I was adding that in /usr/local/hestia/data/templates/web/nginx/php-fpm I created a template i named cable.tpl and cable.stpl

Isn’t that correct?

Where can I find nginx.ssl.conf_xxx ? I should be creating it myself?

Yes, if you have created your own templates, that is the best way to do it.

Those templates are creating the nginx conf files in /home/USER/conf/web/DOMAIN/ so double check those nginx files to view that modified templates are being used.

Okay thanks!

What do you mean by “double check”?

I have opened and saved (without modifying) those nginx.conf files, and it suddenly worked, so I added another redirection for https:// www. and did the same things, but this one doesn’t work atm!

Is there a wait time or something like that?

I meant that you should check that the changes you are adding to your templates, are writen to real nginx conf files.

When you modify a template, you must rebuild the web domains that are using it.

In Web UI:

Edit Web domain and change current template (cables) to another one, save, edit again the domain and change back the template to cables and save it.


Select the web domain and in the drop down list select Rebuild and then Apply using ().

In command line:
v-rebuild-web-domain USER DOMAIN

By the way, I’ve tested it and the redirection is not working right now using

1 Like


I didn’t had this one thank you so much that was it!

Thaaannks I just had to rebuild

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.