Search

Moving Apache Redirect and RewriteRule lines to nginx

Moving Apache Redirect and RewriteRule lines to nginx

Apache Redirect 301 /old /new is a prefix match. nginx wants a rewrite with a capture for the rest of the path, or a return 301. RewriteRule with [R=301,L] is closer to rewrite ... permanent. RewriteEngine On is not a thing you translate; nginx is already rewriting.

Also Read: SEO and Web

Flags that have a mapping

R / R=301 become redirect or permanent. L is last. NC can be a (?i) prefix because nginx rewrite is PCRE. QSA is $is_args$args. HTTPS-off plus a host rewrite is an if ($scheme = http) / if ($host ~* ^www\.(.+)$) pair, not a mystery.

Also Read: SEO: UTM parameters that

The .htaccess to nginx converter maps those directives and lists everything else as skipped: Options, Deny, Header, unknown flags. Skipped is the feature. A silent drop is how you lose a decade of marketing URLs on cutover night.

Also Read: Why Slack and iMessage show the wrong title for your post

After the redirects, the crawlers

When the host moves, robots.txt and the sitemap still need to be valid on the new origin. That is a separate pass with the robots.txt and sitemap validator. Do not put the old Apache ErrorDocument 404 into nginx as a rewrite loop.

Test three URLs by hand after deploy: an exact old path, a prefix match with a tail, and a www-to-apex HTTPS hop. If those three work, the rest of a typical blog .htaccess usually does.

Tags:
TWT Staff

TWT Staff

Writes about Programming, tech news, discuss programming topics for web developers (and Web designers), and talks about SEO tools and techniques

Your experience on this site will be improved by allowing cookies Cookie Policy