<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 14/02/2015 21:57, JACK LINKERS
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAHue+vKcPhuEz9c6yv2+622Q31MfAZubvhYNP6yfm8buwmNO_w@mail.gmail.com"
      type="cite">
      <div dir="ltr"><span style="font-size:12.8000001907349px">Hello,</span>
        <div style="font-size:12.8000001907349px"><br>
        </div>
        <div style="font-size:12.8000001907349px">I need to redirect
          some URLs after redesigning my website.</div>
        <div style="font-size:12.8000001907349px">I use a 301 redirect
          for HTTP to HTTPS protocole :</div>
        <div style="font-size:12.8000001907349px"><br>
        </div>
        <div style="font-size:12.8000001907349px">
          <div><span style="white-space:pre-wrap"> </span>if ($scheme =
            "http") {</div>
          <div><span style="white-space:pre-wrap"> </span>return 301
            <a class="moz-txt-link-freetext" href="https://$server_name$request_uri">https://$server_name$request_uri</a>;</div>
          <div><span style="white-space:pre-wrap"> </span>}</div>
        </div>
        <div style="font-size:12.8000001907349px"><br>
        </div>
        <div style="font-size:12.8000001907349px">But how do I redirect
          URLs that have been changed ?</div>
        <div style="font-size:12.8000001907349px">ie. <a
            moz-do-not-send="true"
            href="https://mywebsite.com/oldname.html" target="_blank">https://mywebsite.com/oldname.html</a> to <a
            moz-do-not-send="true"
            href="https://mywebsite.com/newname.html" target="_blank">https://mywebsite.com/newname.html</a></div>
        <div style="font-size:12.8000001907349px"><br>
        </div>
        <div style="font-size:12.8000001907349px">I did try </div>
        <div style="font-size:12.8000001907349px"><br>
        </div>
        <div style="font-size:12.8000001907349px">
          <div>   if ( $request_filename ~ oldname.html/ ) {</div>
          <div>      rewrite ^ <a moz-do-not-send="true"
              href="https://mywebsite.com/newname.html/" target="_blank">https://mywebsite.com/newname.html/</a>?
            permanent;</div>
          <div>   }</div>
        </div>
        <div style="font-size:12.8000001907349px"><br>
        </div>
        <div style="font-size:12.8000001907349px">But this doesn't work.</div>
        <div style="font-size:12.8000001907349px"><br>
        </div>
        <div style="font-size:12.8000001907349px">My website is hosted
          on a server with Direct Admin runing on a CentOS with Nginx as
          webserver. Don't know if it helps.</div>
        <div style="font-size:12.8000001907349px"><br>
        </div>
        <div style="font-size:12.8000001907349px">Thanks in advance for
          help</div>
      </div>
      <br>
    </blockquote>
    Hi Jack,<br>
    <br>
    I'm no nginx expert, but I think you should use location instead of
    if, its faster and less prone to create other errors. <br>
    I think you can also use 301 redirects. <br>
    <br>
    I would proceed to set up lots of  location clauses thus:<br>
    <br>
    location = /oldurl$ {<br>
        return 301 <a class="moz-txt-link-freetext" href="https://$server_name/newurl">https://$server_name/newurl</a>;<br>
    }    <br>
    <br>
    Hope this works for you<br>
    <br>
    Ian<br>
    <pre class="moz-signature" cols="72">-- 
Ian Hobson 
Mid Auchentiber, Auchentiber, Kilwinning, North Ayrshire KA13 7RR
Tel: 0203 287 1392     
Preparing eBooks for Kindle and ePub formats to give the best reader experience.</pre>
  </body>
</html>