Report this

What is the reason for this report?

NGINX www and non-www url standardization/canonicalization

Posted on April 24, 2013

I can’t seem to get url standardization to work with nginx, the service restarts fine, so i assume the code is sound just not doing what i want it to do. Does this look right for the server blocks? I’ve also tried return instead of rewrite.

server { listen 80; server_name www.example.com; rewrite ^ $scheme://example.com$request_uri permanent; } server { listen 80; server_name example.com; root /usr/share/nginx/www/example.com; index index.php index.html index.htm;

etc…



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

This is not the place for this.

ok, sorry, can you remove it then

Your 301 redirect www to non-www

<br>server { <br> listen 80; <br> server_name www.example.com; <br> return 301 $scheme://example.com$request_uri; <br>} <br> <br># Your Server <br>server { <br>listen 80; <br>server_name example.com; <br>root /link/to/your/website/root; <br>index index.php index.html index.htm; <br>…etc <br>} <br>

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.