M
M
mr_drinkens892014-10-09 12:04:27
Nginx
mr_drinkens89, 2014-10-09 12:04:27

How to properly redirect nginx?

Hello. Tell me, nginx gurus.
How to make a 301 redirect? It is necessary for SEO. There are pages like goods/2, for each of them you need to register a redirect, for example, to /shlang-inekcionnyj.
Tried this option:

rewrite ^(/goods/2)(.*)$   /shlang-inekcionnyj/$2 permanent;

Sometimes it works, sometimes it doesn't.
I read that you can do it this way:
server_name  site.ru/category/articleID-articleName/;
rewrite ^ site.ru/category/articleID/$request_uri? permanent; #301 redirect

Which path is correct, please?
thank.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Makaveli, 2014-10-09
@Makaveli

And you are not tormented for each product to prescribe url? there must be a correspondence between the id number of the product and its CNC. Perhaps it's easier to write a few lines of code on the server side in the site engine? If you go to goods/2 - get the product with id2, look at its url and make the 301 redirect code. For example in PHP:

header( 'Location: http://your.site/goods/' . $goodUrl, TRUE, 301 );

M
mr_drinkens89, 2014-10-09
@mr_drinkens89

It turns out that everything is easier than ever.
like this: rewrite ^/old address/& http://new address;
thanks to all

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question