Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h1>HTTP Solution</h1> <p>From the <a href="http://nginx.org/en/docs/http/converting_rewrite_rules.html">documentation</a>, "the right way is to define a separate server for example.org":</p> <pre><code>server { listen 80; server_name example.com; return 301 http://www.example.com$request_uri; } server { listen 80; server_name www.example.com; ... } </code></pre> <h1>HTTPS Solution</h1> <p>For those who want a solution including <code>https://</code>...</p> <pre><code>server { listen 80; server_name www.domain.com; # $scheme will get the http protocol # and 301 is best practice for tablet, phone, desktop and seo return 301 $scheme://domain.com$request_uri; } server { listen 80; server_name domain.com; # here goes the rest of your config file # example location / { rewrite ^/cp/login?$ /cp/login.php last; # etc etc... } } </code></pre> <p>Note: I have not originally included <code>https://</code> in my solution since we use loadbalancers and our https:// server is a high-traffic SSL payment server: we do not mix https:// and http://.</p> <hr> <p>To check the nginx version, use <code>nginx -v</code>. </p> <p><strong>Strip www from url with nginx redirect</strong></p> <pre><code>server { server_name www.domain.com; rewrite ^(.*) http://domain.com$1 permanent; } server { server_name domain.com; #The rest of your configuration goes here# } </code></pre> <p>So you need to have TWO server codes.</p> <p><strong>Add the www to the url with nginx redirect</strong></p> <p>If what you need is the opposite, to redirect from domain.com to www.domain.com, you can use this:</p> <pre><code>server { server_name domain.com; rewrite ^(.*) http://www.domain.com$1 permanent; } server { server_name www.domain.com; #The rest of your configuration goes here# } </code></pre> <p>As you can imagine, this is just the opposite and works the same way the first example. This way, you don't get SEO marks down, as it is complete perm redirect and move. The no WWW is forced and the directory shown!</p> <h2>Some of my code shown below for a better view:</h2> <pre><code>server { server_name www.google.com; rewrite ^(.*) http://google.com$1 permanent; } server { listen 80; server_name google.com; index index.php index.html; #### # now pull the site from one directory # root /var/www/www.google.com/web; # done # location = /favicon.ico { log_not_found off; access_log off; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload