Welcome to Centmin Mod Community
Register Now

Nginx How to redirect sudomain to external url?

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by Mrbo, Mar 24, 2019.

  1. Mrbo

    Mrbo Member

    97
    7
    8
    Jun 17, 2018
    Ratings:
    +7
    Local Time:
    1:50 AM
    Hi! Im migrating a website for a client. The website was on a apache webbhotell. There was a folder with a index file pointing to an external url. How do I do it with centminmod?

    If I for example want the url sub.mywebsite.com to redirect to centminmod.com.
    ( The domain uses cloudflare )
     
  2. eva2000

    eva2000 Administrator Staff Member

    39,800
    8,775
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,508
    Local Time:
    4:50 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    does index file do the redirect to extenal url ? if it does then you wouldn't have to do anything as the index file i.e. php file redirects via php code to external url, then the php file will do the same with centmin mod.
     
  3. Mrbo

    Mrbo Member

    97
    7
    8
    Jun 17, 2018
    Ratings:
    +7
    Local Time:
    1:50 AM
    The structure is the same as it was on the webbhotell but it doesnt seem to work.

    The subdomain is called j4. So there is a folder in the public/ named j4 and inside it there is a index.php file with this redirect but I just get an error when visiting it. Did I do something wrong?

    Code:
    <?php
    header("location:https://100.20.120.50/login");
    exit;
    ?>
    I found this way to do it in cloudflare. I dont know which is the correct way or if it matters?
     
    Last edited: Mar 24, 2019
  4. Jimmy

    Jimmy Premium Member Premium Member

    1,528
    316
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +779
    Local Time:
    2:50 PM
    1.15.x
    MariaDB 10.3.x
    Why have the server work any harder? Just forward the subdomain on Cloudflare w/ the guide you posted.
     
    • Like Like x 1
  5. eva2000

    eva2000 Administrator Staff Member

    39,800
    8,775
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,508
    Local Time:
    4:50 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    looks good only diff for my php redirects is i use uppercase L in location not sure if that matters

    but yes instead of using php use nginx for redirect might be better

    Have you checked out these guides ?
     
    • Like Like x 1
  6. Mrbo

    Mrbo Member

    97
    7
    8
    Jun 17, 2018
    Ratings:
    +7
    Local Time:
    1:50 AM
    Awesome. Thanks! That was exactly what i was looking for.
    One upside with it is that cloudflare only has 3 free rules.
     
..