Search

Programming
Programming

We provide developers and engineers the guides and tutorials they...

Content
Content

Content is king. It's not just about how you're going to write, b...

Events
Events

Looking for an engaging connection with thousands of other people...

Moving Apache Redirect and RewriteRule lines to nginx

Moving Apache Redirect and RewriteRule lines to nginx

Redirect, RedirectMatch, and common RewriteRule flags have nginx equivalents. RewriteEngine does not. Anything you cannot map should stay on a skipped list, not disappear.

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

About author

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

View all posts (402)
Your experience on this site will be improved by allowing cookies Cookie Policy