0

I have some 100 or so URLs that need to be permanently redirected from static HTML to dynamic pages served by Wordpress. All examples for Nginx 301 redirection I found suggest that each redirect should be defined as its own server block.

However, I have found out that multiple redirects within one server block work as well such as in this simplified configuration:

server { listen 80; server_name www.example.com; root /var/www/; location = /subdir/red1.html { return 301 /subdir/?p=1; } location = /subdir/red2.html { return 301 /subdir/?p=2; } location = /subdir/red3.html { return 301 /subdir/?p=3; } 

}

Curl -I confirms the 301 code. The redirects take place. I prefer this configuration to the one with one server block per redirect because human readability is better. But does this configuration lack something that I'd otherwise have if each redirect was in its own server block?

1 Answer 1

1

Well, execrpts you found are probably dealing with http to https redirections where it makes sense not to have anything more in the server block because the vhost is only there to redirect to an other domain. That's completely wrong to pick random examples and take them as a rules of thumb instead of refering to the official documentation.

100 redirects is not a huge count, you could even use permanent rewrites in one unique server block and group them with regexs.

server { server_name www.example.com; root /var/www/; location /subdir/ { rewrite ^/subdir/red([1-3])\.html /subdir/?p=$1 permanent; } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.