Nginx 301 redirect examples

Here's an example of how to do a 301 Redirect with Nginx:

rewrite /blog/Content/2/8/581 /blog/post/java/dos-batch-files-compile-run-java-program-create-jar-file permanent;

As you can see, Nginx uses the keyword permanent instead of 301.

I just did a few hundred of these on this website. I put them in a separate redirects.conf file, and included that file into my main nginx.conf file like this:

include redirects.conf;

I put that include line in the server section of my main nginx.conf file.

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.