Why redirects live in the server config
Nginx has no .htaccess files like Apache. Rules sit in the server configuration, and after every change you reload it. That means you need access to your VPS or hosting, but in return the 301 response is fast and predictable.
For SEO, redirects matter in three common situations: the site moves to https, you pick one main address (with or without www), or page URLs change after a redesign. A 301 tells the search engine the new address is permanent and helps carry over the page's accumulated value. People arriving from old links in Instagram, OLX listings, Telegram channels or email campaigns also land on a real page instead of a 404.
Return or rewrite: which one to use
The return directive sends a status code and a new address straight away. Rewrite works with a regular expression and is useful when part of a path has to be mapped by a pattern. A simple rule: if return is enough, use return, because the config stays easier to read.
The most common trap is the flag. A rewrite without permanent or redirect does an internal rewrite: the address in the browser does not change and search engines see no redirect at all. Permanent gives a 301, redirect gives a temporary 302. For a page that has moved for good, you want the 301.
Nginx redirect for www and https: one hop only
Move every non-primary version of your address into its own server block that does nothing but redirect. The main block then serves a single address, for example https://example.uz.
server { listen 80; listen 443 ssl; server_name www.example.uz; # certificate that also covers www return 301 https://example.uz$request_uri; } server { listen 80; server_name example.uz; return 301 https://example.uz$request_uri; }
The $request_uri variable keeps the path and query string, so a visitor lands on the same page rather than the homepage. Every variant should reach the final address in one step. Check the certificate too: if it does not cover www, the browser shows a warning before the redirect can even happen.
Moving a single page or a whole section
For one page, an exact-match location with an equals sign is enough. Say an online shop merged two delivery pages into one:
location = /delivery-tashkent/ { return 301 /delivery/; } location ^~ /articles/ { rewrite ^/articles/(.*)$ /blog/$1 permanent; }
The second rule moves the whole section and keeps the rest of the path. Point each old page to the closest matching new page, not to the homepage. Mass redirects to the homepage are often treated by search engines as soft 404 errors.
Hundreds of URLs after a redesign: use map
When the whole catalogue changes addresses, writing hundreds of location blocks is painful. The map directive matches old addresses to new ones from a table, which you can keep in a separate file and generate from a spreadsheet.
map $uri $new_uri { default ""; include /etc/nginx/redirects.map; } server { if ($new_uri) { return 301 $new_uri$is_args$args; } }
The key here is $uri rather than $request_uri, so utm tags from your ads do not break the match, and we append them back to the new address. An if with a single return at server level is safe, but building complex logic inside location blocks is best avoided.
Where loops and chains come from
When a browser reports too many redirects, a rule is firing on the destination address as well. The cause is usually one of these:
- a proxy or Cloudflare handles https itself and passes plain http to nginx, so nginx sends the request to https again
- a trailing-slash rule fights with an application that strips the slash
- the same rule is written both in the outer nginx and inside a Docker container
- a catch-all rule catches sitemap.xml and robots.txt, so those files stop opening
- after a second migration, old redirects point to addresses that are themselves outdated, creating a multi-step chain
Applying changes, testing and getting help
Keep Click and Payme payment URLs and your Telegram bot webhook out of general rules and test them separately, since a redirect on such requests can easily break processing.
A safe workflow: save a copy of the current configuration, check the syntax with nginx -t, then reload gracefully instead of stopping the server. Next, run curl -I on the mirrors and on old and new URLs, and confirm each path is a single hop. Open the site in an incognito window and check pages that must not redirect. After launch, watch your Search Console reports.
Redirects are tied to site structure, the sitemap, canonical URLs and ad links. If you are planning a migration or are unsure about your current rules, the markdev team can audit them and set everything up without losing positions as part of SEO optimisation in Uzbekistan. Describe your task and we will talk through where to start.
FAQ
Should I use 301 or 302 when a page moves?
Use 301 for a permanent move. A 302 signals a temporary redirect, and search engines may keep showing the old address.
Is return better than rewrite in nginx?
If you only need to point to a new address, use return. Rewrite is for cases where part of the path is mapped by a pattern, such as a renamed section.
Why does my browser say there are too many redirects after a change?
A rule is also firing on the destination URL. Most often a proxy in front of nginx passes the request over http, or a trailing-slash rule conflicts with the application.
Do I need to stop the server to apply new rules?
No. Check the syntax with nginx -t first, then do a graceful reload. Existing connections are not dropped.
Let’s look at your task for free
Leave your contact — in a 15-minute call we’ll show where leads get lost and what to fix first.