
Preload vs Preconnect: Which Resource Hint to Use and When
Preload vs preconnect explained: when to use each resource hint, the crossorigin and as mistakes that waste them, and how many hints…
Read article
This guide is for site owners, developers and SEOs who manage redirects on Apache or Nginx, or who are moving a site from one to the other. You will learn how Nginx vs Apache redirects differ in syntax and behaviour, which small differences break rules after a migration, and how to test that every old URL still lands in the right place.
Apache redirects usually live in .htaccess files and use Redirect or RewriteRule with [R=301], while Nginx redirects live in the server configuration and use return or rewrite with the permanent flag. Google only sees the status code, so a 301 means the same on both. The risks are syntax details: leading slashes, query strings and default 302s.

The difference is where the rules live and how they match, not what Google receives. Apache can read rules from .htaccess files in each folder, through two modules: mod_alias for simple Redirect lines and mod_rewrite for RewriteRule patterns. Nginx has no per-folder files. Its rules sit in the server block of its configuration file, and the nginx.org beginner’s guide notes that changes “will not be applied until the command to reload configuration is sent”.
For search engines the result is identical. Google’s redirects documentation shows examples for both servers and treats the status code as the signal: for 301 and 308, “the indexing pipeline uses the redirect as a signal that the redirect target should be canonical”, while 302, 303 and 307 are temporary. If both servers send the same code and target, the result in Google Search is the same.
| Task | Apache (.htaccess) | Nginx (server block) |
|---|---|---|
| One URL, permanent | Redirect 301 /old /new | location = /old { return 301 /new; } |
| Pattern, permanent | RewriteRule ^blog/(.*)$ /news/$1 [R=301,L] | rewrite ^/blog/(.*)$ /news/$1 permanent; |
| Temporary | [R] or Redirect temp (302) | rewrite … redirect; or return 302 |
| 307 or 308 | [R=307] or [R=308] | return 307 or return 308 |
| Page removed | Redirect gone /old | return 410; |
| Case-insensitive | [NC] | (?i) in rewrite, ~* in if |
| Drop the old query string | [QSD] or a target with ? | Target ending with ? |
| Where the rule lives | .htaccess or server config | server block, applied after a reload |
Use the Redirect directive for simple moves and RewriteRule only when you need patterns or conditions. Apache’s own guide to when not to use mod_rewrite says simple redirection “should be accomplished using these directives rather than RewriteRule”. A line such as Redirect 301 /old-page/ https://example.com/new-page/ is a prefix match: the mod_alias docs say “Additional path information beyond the matched URL-path will be appended to the target URL”, and the query string is passed along too.
Watch the defaults. If you leave out the status, Apache sends a temporary 302, both for Redirect and for RewriteRule with a bare [R] flag. For SEO moves, always write 301 or permanent explicitly. If you need a quick, correct rule, the .htaccess redirect generator writes it for you.
Use return for a fixed target and rewrite for a pattern. location = /old-page/ { return 301 https://example.com/new-page/; } answers one exact URL. rewrite ^/blog/(.*)$ /news/$1 permanent; moves a whole section, because in the ngx_http_rewrite_module docs the permanent flag “returns a permanent redirect with the 301 code” and the redirect flag returns a 302.
Two details matter. First, rewrite only sends 301 or 302, so 307 and 308 need return. Second, rewrite appends the original query string by default, and the docs say that “putting a question mark at the end of a replacement string avoids having them appended”. The Nginx redirect generator builds single rules in this format.
Because Apache in .htaccess matches a shorter string than Nginx does. Apache’s per-directory rewrite docs say “the directory prefix is stripped”, so a root .htaccess rule sees blog/post with no leading slash, and a pattern beginning with ^/ “will never match in this context”. Copy ^blog/(.*)$ into Nginx unchanged and it never matches, because Nginx sees /blog/post.
The Apache to Nginx redirect converter handles these differences line by line and flags what it cannot convert safely, such as proxies, -f and -d file checks and <Files> containers.
Pick one pattern and enforce it with a single 301 rule on whichever server you run. Google’s post on trailing slashes says Google “treats each URL above separately (and equally)”, so /services and /services/ are two URLs when both load. The root is the exception: the home page with and without the slash is the same URL. My guide on trailing slashes and SEO covers the choice in more detail.
The servers behave differently here. Apache’s mod_dir redirects a request for a real folder without a slash to the version with the slash, so a remove slash rule must skip real folders. Nginx only redirects when your rules say so. The trailing slash checker finds mixed URLs in a crawl export and writes matching rules for both servers, using the same regular expression in each.
Test before you switch traffic, then again after. Run nginx -t to check the syntax, reload on a staging server, and request your old URLs with curl -I. Compare the status code and Location header with what the Apache server returns today: they should match exactly, including the query string.
Then crawl the redirected list and look for hops. A rule that redirects to a URL that redirects again creates a chain, which my guide on fixing redirect chains explains how to flatten. Check that permanent moves really use 301 or 308, as covered in 301 vs 302 redirects, and watch Search Console for redirect errors in the weeks after the move.
Example: a 30 page brochure site on example.com moves from shared Apache hosting to an Nginx server. Its .htaccess file has 12 lines. Pasted into the Apache to Nginx redirect converter, 10 lines are read and 6 redirect rules convert, including an HTTPS and www rule with two [OR] conditions and a RewriteRule with [NC]. One Header line is flagged, because it is not a redirect, and is moved by hand. A crawl export of 10 URLs in the trailing slash checker shows 7 page URLs, 4 with a slash and 3 without, and 1 duplicate pair: /services and /services/ both return 200. The owner keeps the slash pattern, adds the generated Nginx rule, runs nginx -t, and checks every old URL with curl before switching DNS.
No. Google only sees the HTTP status code and the target URL, not the server software. A 301 from Nginx and a 301 from Apache are treated the same way, as a permanent move that signals the target should be canonical.
Use return when the target is fixed, such as one old page to one new page, because it is simple and clear. Use rewrite when you need a regular expression with captures, such as moving a whole folder.
You can keep the file, but Nginx will ignore it. Nginx reads rules from its own configuration file, and changes apply after a reload. Every redirect you still need must be converted and added to the server block.
No. Google treats 301 and 308 the same way: both are permanent redirects that signal the target should be canonical. For normal page moves either code works, so use the one your server setup makes simplest.
Because 302 is the default. A Redirect line with no status and a RewriteRule with a bare [R] flag both send a temporary 302. Add 301 or permanent to Redirect, or use [R=301] on RewriteRule.
Google’s redirect page sets no fixed time and says to use permanent redirects when you are sure they will not be reverted. Keep them as long as old URLs still get links, bookmarks or traffic, which for many sites means years.
This guide is part of my technical SEO audit checklist.
Checked 23 Oct 2026. Facts checked against these official pages. Read how I check facts in my editorial policy.
Moving servers and worried about redirects? See my technical SEO service.

Preload vs preconnect explained: when to use each resource hint, the crossorigin and as mistakes that waste them, and how many hints…
Read article
Search Console regex filters explained: RE2 rules, case sensitivity, and copy ready examples for questions, brand, long-tail queries and URL folders.
Read article
QAPage vs DiscussionForumPosting schema: Google's rule for choosing, what each type requires, which pages qualify for neither, and how to test the…
Read articleSend your website and I will reply with a free audit.