How to redirect url with complete slug in easyengine + nginx + html


#1

Hello friends! :laughing:

I have a problem to several days without solution.

I created a subdomain sub.example.com.

To redirect all urls of this subdomain (www to no-www), put the following code into the server (/etc/nginx/sites-available/sub.example.com):

server_name www.sub.example.com; return 301 $scheme://sub.example.com$request_uri;

I saved the file and restarted the nginx.

Once configured normally redirects www.sub.example.com to sub.example.com

The problem is that when an entire slug does not redirect and gives 404, in both cases below:

www.sub.example.com/post-1.html to sub.example.com/post-1.html

www.sub.example.com/img/image.jpg to sub.example.com/img/image.jpg

Can anyone give me a light for me to see what I’m doing wrong?

Thanks!

TRADUZIDO DE:

Olá amigos! Estou com um problema a varios dias sem solução.

Criei um subdominio sub.example.com

Para redirecionar todas as urls desse subdominio (de www para no-www), coloquei o seguinte codigo dentro do server (/etc/nginx/sites-available/sub.example.com):

CODIGO

Salvei o arquivo e reiniciei o nginx.

Depois de configurado redireciona normalmente de www. sub.example.com para sub.example.com

O problema é que quando é uma slug inteira não redireciona e ainda dá erro 404, em ambos os casos abaixo:

www. sub.example.com/post-1.html para sub.example.com/post-1.html

www. sub.example.com/img/image.jpg para sub.example.com/img/image.jpg

Alguem pode me dá uma luz pra mim ver o que estou fazendo de errado?


#2

Have you try adding a (www) CNAME to your Domain in your DNS settings?


#3

Hello sinewaves, thanks for the tip.

I had not put the cname (www) because I had a “record A” with a wildcard (*). Hence I thought only that resolved.

I added the cname now and is redirecting all slugs. Everything okay at that point now.

But still giving 404 error, even with correct slug and the image properly hosted on the server. Any more suggestions?

Thank you very much in advance.

TRADUZIDO DE:

Olá sinewaves, obrigado pela dica.

Eu não havia colocado o cname (www) porque já tinha um “record A” com um caractere coringa (*). Daí pensava que só isso resolvia.

Adicionei o cname agora e está redirecionando todas as slugs. Tudo ok nesse ponto agora.

Pórem continua dando erro 404, mesmo com a slug correta e a imagem devidamente hospedada no servidor. Mais alguma sugestão?

Desde já agradeço.


#4

With fictitious information, my dns settings are as in attached print:


#5

Did you update your host file by adding your ip and example.com to the list? www/root/etc/host


#6

Hi,

The nginx server was configured with easyengine. I did not find this way you suggest. The server is Debian 7.


#7

You will need to set up a SFTP using like filezilla first, then you can access and modify your Debian root file system. I found this tutorial it may help to do this if your not familiar.


#8

I already have installed SFTP client.

What I said is that I not found the folder: “host” in / etc /

Which of these folders below you refer?

/root/

/var/www/

Or refers to some of these files?

/etc/host.conf

/etc/hosts

Sorry so many questions. It is that I am still in the process of adaptation with nginx. :smirk:


#9

If you navigate to the root folder you will see the etc folder inside that directory you will see your host.conf or host file that file you will need to add the ip & your example.com in the list, restart nginx that’s it.


#10

sinewaves, finally I managed to solve. :slight_smile:

I will leave here the solution found to this issue. If you have someone else with this problem may be useful.

In your SFTP manager navigate to: /etc/nginx/conf.d

Within this directory, create a .conf file can be for example: redirect.conf

server_name www.sub.example.com; return 301 $scheme://sub.example.com$request_uri;

And then within the redirect.conf place the code, save and restart nginx.

If all went well, you are done magic. :smiley:

Thanks for your help sinewaves.


#11

thanks


#12

Glad to hear it, And thanks for the final solution. Cheers mate!


#13