LMSouq
server-admin Open

How to redirect a URL in Nginx

AM
Amal Kumar S
1 month ago
3 views
Problem Description
I need to redirect every http://test.com request to http://www.test.com. How can this be done. In the server block I tried adding rewrite ^/(.*) http://www.test.com/$1 permanent; but in browser it says > The page isn't redirecting properly > > Firefox has detected that the server is redirecting the request for this address in a way that will never complete. My server block looks like server { listen 80; server_name test.com; client_max_body_size 10M; client_body_buffer_size 128k; root /home/test/test/public; passenger_enabled on; rails_env production; #rewrite ^/(.*) http://www.test.com/$1 permanent; #rewrite ^(.*)$ $scheme://www.test.com$1; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base