nginx: Multiple cross-domain 301 redirects with different page addressesnginx rewrite for an url with parametersBlank Page: wordpress on nginx+php-fpmCan not change nginx 1.2.5 default websiteDomino SSL 301 redirect with www and non wwwnginx 302 redirect only naked IPnon www to www domain?Why rewrite(nginx) redirects with 301 code?CodeIgniter nginx rewrite rules for i8ln URL'sConfigure NGINX : How to handle 500 Error on upstream itself, While Nginx handle other 5xx errorsWhy Nginx calls for invalid certificate in non-existent subdomains just to redirect to 404?Nginx reverse proxy to many local servers + webserver duty

Can a black dragonborn's acid breath weapon destroy objects?

Does an ice chest packed full of frozen food need ice?

If you had a giant cutting disc 60 miles diameter and rotated it 1000 rps, would the edge be traveling faster than light?

What is wrong with this proof that symmetric matrices commute?

Inconsistent behavior of compiler optimization of unused string

When 2-pentene reacts with HBr, what will be the major product?

How to tell your grandparent to not come to fetch you with their car?

The eyes have it

How to officially communicate to a non-responsive colleague?

Why doesn't Adrian Toomes give up Spider-Man's identity?

How can I most clearly write a homebrew item that affects the ground below its radius after the initial explosion it creates?

At what point in time did Dumbledore ask Snape for this favor?

What does the term "railed" mean in signal processing?

Which comes first? Multiple Imputation, Splitting into train/test, or Standardization/Normalization

How to chain Python function calls so the behaviour is as follows

My coworkers think I had a long honeymoon. Actually I was diagnosed with cancer. How do I talk about it?

Do any instruments not produce overtones?

Why was the Sega Genesis marketed as a 16-bit console?

Interview not reimboursed if offer is made but not accepted

Smooth switching between 12 V batteries, with a toggle switch

What can I, as a user, do about offensive reviews in App Store?

How to project 3d image in the planes xy, xz, yz?

What's the name of this light airplane?

Passing multiple files through stdin (over ssh)



nginx: Multiple cross-domain 301 redirects with different page addresses


nginx rewrite for an url with parametersBlank Page: wordpress on nginx+php-fpmCan not change nginx 1.2.5 default websiteDomino SSL 301 redirect with www and non wwwnginx 302 redirect only naked IPnon www to www domain?Why rewrite(nginx) redirects with 301 code?CodeIgniter nginx rewrite rules for i8ln URL'sConfigure NGINX : How to handle 500 Error on upstream itself, While Nginx handle other 5xx errorsWhy Nginx calls for invalid certificate in non-existent subdomains just to redirect to 404?Nginx reverse proxy to many local servers + webserver duty






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm moving my old site over to a new domain, and with that new domain comes new naming conventions. I'm trying to figure out what would be the simplest way of accomplishing the following for roughly 8 different pages:




  1. http to https

  2. Different domain

  3. Redirect (1) old www and (2) old non-www addresses, plus (3) new non-www address to new www address

Here are two old pages from the old domain:



Portfolio:

http://dcturanoinc.com/?dct=portfolio_expediting
http://www.dcturanoinc.com/?dct=portfolio_expediting

Services:

http://dcturanoinc.com/?dct=services_expediting
http://www.dcturanoinc.com/?dct=services_expediting


Here are two new pages from the new domain:



Services:

https://dcturano.com/services/
https://www.dcturano.com/services/

Portfolio:

https://dcturano.com/portfolio/
https://www.dcturano.com/portfolio/


EDIT: This is my nginx.conf file as it currently stands.



server {
listen 80;
listen [::]:80;
listen 443 default_server ssl;

server_name dcturano.com www.dcturano.com;

if ($scheme = http)
return 301 https://$server_name$request_uri;










share|improve this question
























  • Possible duplicate of this

    – wurtel
    Nov 12 '14 at 10:04











  • Not a duplicate of that question. Also, updated the OP to be more specific.

    – eclipsis
    Nov 13 '14 at 3:07

















0















I'm moving my old site over to a new domain, and with that new domain comes new naming conventions. I'm trying to figure out what would be the simplest way of accomplishing the following for roughly 8 different pages:




  1. http to https

  2. Different domain

  3. Redirect (1) old www and (2) old non-www addresses, plus (3) new non-www address to new www address

Here are two old pages from the old domain:



Portfolio:

http://dcturanoinc.com/?dct=portfolio_expediting
http://www.dcturanoinc.com/?dct=portfolio_expediting

Services:

http://dcturanoinc.com/?dct=services_expediting
http://www.dcturanoinc.com/?dct=services_expediting


Here are two new pages from the new domain:



Services:

https://dcturano.com/services/
https://www.dcturano.com/services/

Portfolio:

https://dcturano.com/portfolio/
https://www.dcturano.com/portfolio/


EDIT: This is my nginx.conf file as it currently stands.



server {
listen 80;
listen [::]:80;
listen 443 default_server ssl;

server_name dcturano.com www.dcturano.com;

if ($scheme = http)
return 301 https://$server_name$request_uri;










share|improve this question
























  • Possible duplicate of this

    – wurtel
    Nov 12 '14 at 10:04











  • Not a duplicate of that question. Also, updated the OP to be more specific.

    – eclipsis
    Nov 13 '14 at 3:07













0












0








0








I'm moving my old site over to a new domain, and with that new domain comes new naming conventions. I'm trying to figure out what would be the simplest way of accomplishing the following for roughly 8 different pages:




  1. http to https

  2. Different domain

  3. Redirect (1) old www and (2) old non-www addresses, plus (3) new non-www address to new www address

Here are two old pages from the old domain:



Portfolio:

http://dcturanoinc.com/?dct=portfolio_expediting
http://www.dcturanoinc.com/?dct=portfolio_expediting

Services:

http://dcturanoinc.com/?dct=services_expediting
http://www.dcturanoinc.com/?dct=services_expediting


Here are two new pages from the new domain:



Services:

https://dcturano.com/services/
https://www.dcturano.com/services/

Portfolio:

https://dcturano.com/portfolio/
https://www.dcturano.com/portfolio/


EDIT: This is my nginx.conf file as it currently stands.



server {
listen 80;
listen [::]:80;
listen 443 default_server ssl;

server_name dcturano.com www.dcturano.com;

if ($scheme = http)
return 301 https://$server_name$request_uri;










share|improve this question
















I'm moving my old site over to a new domain, and with that new domain comes new naming conventions. I'm trying to figure out what would be the simplest way of accomplishing the following for roughly 8 different pages:




  1. http to https

  2. Different domain

  3. Redirect (1) old www and (2) old non-www addresses, plus (3) new non-www address to new www address

Here are two old pages from the old domain:



Portfolio:

http://dcturanoinc.com/?dct=portfolio_expediting
http://www.dcturanoinc.com/?dct=portfolio_expediting

Services:

http://dcturanoinc.com/?dct=services_expediting
http://www.dcturanoinc.com/?dct=services_expediting


Here are two new pages from the new domain:



Services:

https://dcturano.com/services/
https://www.dcturano.com/services/

Portfolio:

https://dcturano.com/portfolio/
https://www.dcturano.com/portfolio/


EDIT: This is my nginx.conf file as it currently stands.



server {
listen 80;
listen [::]:80;
listen 443 default_server ssl;

server_name dcturano.com www.dcturano.com;

if ($scheme = http)
return 301 https://$server_name$request_uri;







nginx http redirect https 301-redirect






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '14 at 3:07







eclipsis

















asked Nov 12 '14 at 1:53









eclipsiseclipsis

223129




223129












  • Possible duplicate of this

    – wurtel
    Nov 12 '14 at 10:04











  • Not a duplicate of that question. Also, updated the OP to be more specific.

    – eclipsis
    Nov 13 '14 at 3:07

















  • Possible duplicate of this

    – wurtel
    Nov 12 '14 at 10:04











  • Not a duplicate of that question. Also, updated the OP to be more specific.

    – eclipsis
    Nov 13 '14 at 3:07
















Possible duplicate of this

– wurtel
Nov 12 '14 at 10:04





Possible duplicate of this

– wurtel
Nov 12 '14 at 10:04













Not a duplicate of that question. Also, updated the OP to be more specific.

– eclipsis
Nov 13 '14 at 3:07





Not a duplicate of that question. Also, updated the OP to be more specific.

– eclipsis
Nov 13 '14 at 3:07










1 Answer
1






active

oldest

votes


















0














1. HTTP -> HTTPS



To automate detection of HTTP vs HTTPS, I would use 2 separate server blocks:



server 
listen 80 default_server;
listen [::]:80 default_server;

# Redirect to HTTPS


server
listen 443 default_server ssl;
listen [::]:443 default_server ssl;

# Serve content



Redirect will be done through the use of return 301 rather than using rewrite, which is discouraged when avoidable.



2. www.domain -> domain



Now to redirect www to non-www, I would use a map, avoiding to use if:



map $host $new_host 
"~*^www.(?<domain>.+)$" $domain;
default $host;



then use $new_host in combination with return 301



3. ?dct=portfolio_ -> ?dct=services_



Finally, to redirect old domains to new ones, it is the kind of arguments filtering explained on the link provided by @wurtel, although I would once again use a map instead of if.



map $arg_dct $new_arg_dct 
"~*^portfolio_(?<dct>.+)$" services_$dct;
default $arg_dct;



4. All-in-one example



http 
map $host $new_host
"~*^www.(?<domain>.+)$" $domain;
default $host;


map $arg_dct $new_arg_dct
"~*^portfolio_(?<dct>.+)$" services_$dct;
default $arg_dct;


server
listen 80 default_server;
listen [::]:80 default_server;

return 301 https://$new_host/?dct=$new_arg_dct;


server
listen 443 default_server ssl;
listen [::]:443 default_server ssl;

if ($new_host != $host)
# Used $scheme to show you its existence
return 301 $scheme://$new_host/?dct=$new_arg_dct;


if ($new_arg_dct != $arg_dct)
# Used $scheme to show you its existence
return 301 $scheme://$new_host/?dct=$new_arg_dct;





As you noticed, the use of seperate servers is not really necessary here, as a simple return 301 https://[...] redirect would have been sufficient. However, I find it prettier if HTTP requests never made it to the right server. It would also help scale your configuration if you end up with services not (yet) supporting HTTPS.



As for the arguments, I took your provided examples to the letter. If you wish to have some other arguments you do not want to touch and you want to redirect in a generic fashion, you may need to chain several map (or use if if you know what you are doing) to rewrite the $args variable, ending up with a rewritten construction ready to be sent to the redirection URL.






share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "2"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f643677%2fnginx-multiple-cross-domain-301-redirects-with-different-page-addresses%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    1. HTTP -> HTTPS



    To automate detection of HTTP vs HTTPS, I would use 2 separate server blocks:



    server 
    listen 80 default_server;
    listen [::]:80 default_server;

    # Redirect to HTTPS


    server
    listen 443 default_server ssl;
    listen [::]:443 default_server ssl;

    # Serve content



    Redirect will be done through the use of return 301 rather than using rewrite, which is discouraged when avoidable.



    2. www.domain -> domain



    Now to redirect www to non-www, I would use a map, avoiding to use if:



    map $host $new_host 
    "~*^www.(?<domain>.+)$" $domain;
    default $host;



    then use $new_host in combination with return 301



    3. ?dct=portfolio_ -> ?dct=services_



    Finally, to redirect old domains to new ones, it is the kind of arguments filtering explained on the link provided by @wurtel, although I would once again use a map instead of if.



    map $arg_dct $new_arg_dct 
    "~*^portfolio_(?<dct>.+)$" services_$dct;
    default $arg_dct;



    4. All-in-one example



    http 
    map $host $new_host
    "~*^www.(?<domain>.+)$" $domain;
    default $host;


    map $arg_dct $new_arg_dct
    "~*^portfolio_(?<dct>.+)$" services_$dct;
    default $arg_dct;


    server
    listen 80 default_server;
    listen [::]:80 default_server;

    return 301 https://$new_host/?dct=$new_arg_dct;


    server
    listen 443 default_server ssl;
    listen [::]:443 default_server ssl;

    if ($new_host != $host)
    # Used $scheme to show you its existence
    return 301 $scheme://$new_host/?dct=$new_arg_dct;


    if ($new_arg_dct != $arg_dct)
    # Used $scheme to show you its existence
    return 301 $scheme://$new_host/?dct=$new_arg_dct;





    As you noticed, the use of seperate servers is not really necessary here, as a simple return 301 https://[...] redirect would have been sufficient. However, I find it prettier if HTTP requests never made it to the right server. It would also help scale your configuration if you end up with services not (yet) supporting HTTPS.



    As for the arguments, I took your provided examples to the letter. If you wish to have some other arguments you do not want to touch and you want to redirect in a generic fashion, you may need to chain several map (or use if if you know what you are doing) to rewrite the $args variable, ending up with a rewritten construction ready to be sent to the redirection URL.






    share|improve this answer



























      0














      1. HTTP -> HTTPS



      To automate detection of HTTP vs HTTPS, I would use 2 separate server blocks:



      server 
      listen 80 default_server;
      listen [::]:80 default_server;

      # Redirect to HTTPS


      server
      listen 443 default_server ssl;
      listen [::]:443 default_server ssl;

      # Serve content



      Redirect will be done through the use of return 301 rather than using rewrite, which is discouraged when avoidable.



      2. www.domain -> domain



      Now to redirect www to non-www, I would use a map, avoiding to use if:



      map $host $new_host 
      "~*^www.(?<domain>.+)$" $domain;
      default $host;



      then use $new_host in combination with return 301



      3. ?dct=portfolio_ -> ?dct=services_



      Finally, to redirect old domains to new ones, it is the kind of arguments filtering explained on the link provided by @wurtel, although I would once again use a map instead of if.



      map $arg_dct $new_arg_dct 
      "~*^portfolio_(?<dct>.+)$" services_$dct;
      default $arg_dct;



      4. All-in-one example



      http 
      map $host $new_host
      "~*^www.(?<domain>.+)$" $domain;
      default $host;


      map $arg_dct $new_arg_dct
      "~*^portfolio_(?<dct>.+)$" services_$dct;
      default $arg_dct;


      server
      listen 80 default_server;
      listen [::]:80 default_server;

      return 301 https://$new_host/?dct=$new_arg_dct;


      server
      listen 443 default_server ssl;
      listen [::]:443 default_server ssl;

      if ($new_host != $host)
      # Used $scheme to show you its existence
      return 301 $scheme://$new_host/?dct=$new_arg_dct;


      if ($new_arg_dct != $arg_dct)
      # Used $scheme to show you its existence
      return 301 $scheme://$new_host/?dct=$new_arg_dct;





      As you noticed, the use of seperate servers is not really necessary here, as a simple return 301 https://[...] redirect would have been sufficient. However, I find it prettier if HTTP requests never made it to the right server. It would also help scale your configuration if you end up with services not (yet) supporting HTTPS.



      As for the arguments, I took your provided examples to the letter. If you wish to have some other arguments you do not want to touch and you want to redirect in a generic fashion, you may need to chain several map (or use if if you know what you are doing) to rewrite the $args variable, ending up with a rewritten construction ready to be sent to the redirection URL.






      share|improve this answer

























        0












        0








        0







        1. HTTP -> HTTPS



        To automate detection of HTTP vs HTTPS, I would use 2 separate server blocks:



        server 
        listen 80 default_server;
        listen [::]:80 default_server;

        # Redirect to HTTPS


        server
        listen 443 default_server ssl;
        listen [::]:443 default_server ssl;

        # Serve content



        Redirect will be done through the use of return 301 rather than using rewrite, which is discouraged when avoidable.



        2. www.domain -> domain



        Now to redirect www to non-www, I would use a map, avoiding to use if:



        map $host $new_host 
        "~*^www.(?<domain>.+)$" $domain;
        default $host;



        then use $new_host in combination with return 301



        3. ?dct=portfolio_ -> ?dct=services_



        Finally, to redirect old domains to new ones, it is the kind of arguments filtering explained on the link provided by @wurtel, although I would once again use a map instead of if.



        map $arg_dct $new_arg_dct 
        "~*^portfolio_(?<dct>.+)$" services_$dct;
        default $arg_dct;



        4. All-in-one example



        http 
        map $host $new_host
        "~*^www.(?<domain>.+)$" $domain;
        default $host;


        map $arg_dct $new_arg_dct
        "~*^portfolio_(?<dct>.+)$" services_$dct;
        default $arg_dct;


        server
        listen 80 default_server;
        listen [::]:80 default_server;

        return 301 https://$new_host/?dct=$new_arg_dct;


        server
        listen 443 default_server ssl;
        listen [::]:443 default_server ssl;

        if ($new_host != $host)
        # Used $scheme to show you its existence
        return 301 $scheme://$new_host/?dct=$new_arg_dct;


        if ($new_arg_dct != $arg_dct)
        # Used $scheme to show you its existence
        return 301 $scheme://$new_host/?dct=$new_arg_dct;





        As you noticed, the use of seperate servers is not really necessary here, as a simple return 301 https://[...] redirect would have been sufficient. However, I find it prettier if HTTP requests never made it to the right server. It would also help scale your configuration if you end up with services not (yet) supporting HTTPS.



        As for the arguments, I took your provided examples to the letter. If you wish to have some other arguments you do not want to touch and you want to redirect in a generic fashion, you may need to chain several map (or use if if you know what you are doing) to rewrite the $args variable, ending up with a rewritten construction ready to be sent to the redirection URL.






        share|improve this answer













        1. HTTP -> HTTPS



        To automate detection of HTTP vs HTTPS, I would use 2 separate server blocks:



        server 
        listen 80 default_server;
        listen [::]:80 default_server;

        # Redirect to HTTPS


        server
        listen 443 default_server ssl;
        listen [::]:443 default_server ssl;

        # Serve content



        Redirect will be done through the use of return 301 rather than using rewrite, which is discouraged when avoidable.



        2. www.domain -> domain



        Now to redirect www to non-www, I would use a map, avoiding to use if:



        map $host $new_host 
        "~*^www.(?<domain>.+)$" $domain;
        default $host;



        then use $new_host in combination with return 301



        3. ?dct=portfolio_ -> ?dct=services_



        Finally, to redirect old domains to new ones, it is the kind of arguments filtering explained on the link provided by @wurtel, although I would once again use a map instead of if.



        map $arg_dct $new_arg_dct 
        "~*^portfolio_(?<dct>.+)$" services_$dct;
        default $arg_dct;



        4. All-in-one example



        http 
        map $host $new_host
        "~*^www.(?<domain>.+)$" $domain;
        default $host;


        map $arg_dct $new_arg_dct
        "~*^portfolio_(?<dct>.+)$" services_$dct;
        default $arg_dct;


        server
        listen 80 default_server;
        listen [::]:80 default_server;

        return 301 https://$new_host/?dct=$new_arg_dct;


        server
        listen 443 default_server ssl;
        listen [::]:443 default_server ssl;

        if ($new_host != $host)
        # Used $scheme to show you its existence
        return 301 $scheme://$new_host/?dct=$new_arg_dct;


        if ($new_arg_dct != $arg_dct)
        # Used $scheme to show you its existence
        return 301 $scheme://$new_host/?dct=$new_arg_dct;





        As you noticed, the use of seperate servers is not really necessary here, as a simple return 301 https://[...] redirect would have been sufficient. However, I find it prettier if HTTP requests never made it to the right server. It would also help scale your configuration if you end up with services not (yet) supporting HTTPS.



        As for the arguments, I took your provided examples to the letter. If you wish to have some other arguments you do not want to touch and you want to redirect in a generic fashion, you may need to chain several map (or use if if you know what you are doing) to rewrite the $args variable, ending up with a rewritten construction ready to be sent to the redirection URL.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 17 '14 at 11:24









        Bernard RossetBernard Rosset

        1,115920




        1,115920



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Server Fault!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f643677%2fnginx-multiple-cross-domain-301-redirects-with-different-page-addresses%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

            Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

            What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company