#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0

    Subdomain redirect, best practice


    Need second opinion...

    A little background... We recently moved our properties to a new web host. Previously, our web host handled all things DNS... now, that responsibility falls on my shoulders .. I am not a "DNS professional guy" ...

    So, I needed to setup several subdomains which needed to redirect to external sites.

    3 of those subdomains I setup myself using A Records and IP.

    I have 2 other subdomains that need to also point to external sites, but I don't have IP's. And, the URL's look a little 'different'... pointing to a subfolder, parameter in the url, etc.

    So, not knowing the correct approach, I asked our domain host (mydomain) for an assist.

    Their 'solution': they created web pages with iframes.

    Somehow, that doesn't seem right. I challenged them, and their response was, 'There are two methods: iframe and meta refresh...'

    The redirects do work, but both approaches seem like workarounds. (The hosts don't resolve to the proper IP, users can see the actual external site in the browser status bar while launching, etc.) iFrame just doesn't seem like a solid solution.

    Opinions please. What is best practice?

    Thanks much.


    PS I'm not impressed with mydomain... If anyone has feedback, I'd appreciate.
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,055
    Rep Power
    9398
    There are more than two methods, and the two they mentioned aren't that great.

    DNS can only let you "redirect" an entire (sub)domain to an IP address. I used quotes there because it's not actually a redirect, more like if someone asked you for your address and you told them your neighbor's.

    For a true redirect, such as one that goes to a website (not an IP address) or to a specific path of a website, you need a server. Maybe yours, maybe not. That server then has rules set up that say, like, "requests for subdomain.example.com/* get redirected to anotherdomain.com/subdirectory/*". IFRAMEs are horrible because they hide useful information like URLs and prevent people from doing even the most basic of things (copying URLs, bookmarks, refreshing the page...) and meta refreshes are wasteful because you're making the browser actually download a web page containing something that has to be parsed out before the browser realizes that it is supposed to navigate to a new page.

    So your first task is to find yourself a server: your "new web host" can surely do that, but you have to keep pointing all your old domains to that machine. Then you alter the configuration for those domains (yes, your server has to be able to respond to requests for those domains) to do a redirect, such as with Apache's Redirect directive. It's not as efficient as a DNS solution, but if you need something more complicated than just sending people to your neighbor's house then it's the best solution.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0
    Thank you.

    If you don't mind getting more specific . . .

    The first redirect involves 2 servers that I have control of.

    Let's call them:

    -- domain
    -- domain-utility

    ** not allowed to use url's, so I'll abbreviate

    There's an application here: domain-utility/app

    I'd like to access above via a subdomain, like this: app.domain

    So ... app.domain >> domain-utility/app

    More detail please. We're you suggesting a 301 redirect somewhere?

    Thanks again.
    Jim
  6. #4
  7. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,233
    Rep Power
    1469
    Here's a basic explanation. If your server is going to handle your subdomain (i.e. Apache vhost, etc.) then you use an A record to point to the IP address of the server. The request goes to the server, the server determines what to do with the subdomain.

    If you want to point it to a specific URL, you have two options:

    A URL record will redirect to the URL you provide. The address bar will change to reflect the new URL. (This is not actually a DNS record, but most DNS systems provide this feature. Internally, it's just a 301 redirect. You can just as easily handle this from your own server.)

    A CNAME record will redirect to the URL you provide, but the address bar will not change. This is a far better option than the IFRAME method.

    There are probably more ways to achieve this with DNS (ALIAS records as an example), but these are the easiest and most straightforward.

    So in short, A records point to IP addresses and CNAME records point to domains or URLs.

    Comments on this post

    • requinix agrees : URL records? interesting
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0
    Thanks.

    So...

    1. On the parent server I'd create an A Record pointing to the application server IP
    2. On the application server, create a 301 to redirect that incoming 'subdomain url' to the proper sub-folder

    Is that right?

    I 'think' your second method was...

    1. On the parent server I'd create an A Record pointing to the application server IP
    2. On the parent server, create a CNAME record pointing to the specific application server url.
  10. #6
  11. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,233
    Rep Power
    1469
    You would have this.

    A record domain1.com > 11.22.33.44 (server 1)

    A record domain2.com > 44.33.22.11 (server 2)

    CNAME app.domain1.com > domain2.com/app


    So a url like this:

    http://app.domain1.com/some/other/page.html

    redirects to:

    http://domain2.com/app/some/other/page.html

    but the address bar still shows:

    http://app.domain1.com/some/other/page.html

    Unless, of course, server2 uses some type of rewrite.
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  12. #7
  13. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,945
    Rep Power
    4033
    Originally Posted by jmueller0823
    1. On the parent server I'd create an A Record pointing to the application server IP
    2. On the application server, create a 301 to redirect that incoming 'subdomain url' to the proper sub-folder
    Basically. It's a two-part setup. You have your DNS point to the IP of a web server. Then that webserver is configured to issue the redirect. For example if you had an apache server on IP 1.2.3.4, you'd have your DNS such that app.example.com responds with the IP 1.2.3.4

    In your apache configuration you'd have a virtual host for that subdomain which issues the redirect, something like:
    Code:
    <VirtualHost 1.2.3.4:80>
       ServerName app.example.com
       Redirect permanent / http://www.example.com/app
    </VirtualHost>
    When a request for app.example.com comes in, apache would process the Redirect directive which matches any URL beginning with / (ie, every URL) and redirects it to the new URL.

    Depending on what kind of redirection you want, you may need to use a different configuration. The Redirect directive for example will append the requested URL to the new URL so if someone requested http://app.example.com/some/folder/ they would get redirected to http://www.example.com/app/some/folder

    If that is not desirable behaviour then you could use mod_rewrite to issue a redirect without the original target being included.
    Recycle your old CD's, don't just trash them



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  14. #8
  15. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,233
    Rep Power
    1469
    Originally Posted by kicken
    Basically. It's a two-part setup. You have your DNS point to the IP of a web server. Then that webserver is configured to issue the redirect. For example if you had an apache server on IP 1.2.3.4, you'd have your DNS such that app.example.com responds with the IP 1.2.3.4
    This only works if your DNS is configured to use wildcards.

    A record * > 1.2.3.4

    This means that any subdomain that does not have it's own record should be directed back to 1.2.3.4

    An A record for the subdomain itself would also work, but wildcards are the best route if you plan on handling subdomains locally. This way you can add them at any time without having to change DNS.

    For small sites or shared hosts, this ok. For larger sites or dedicated servers, I prefer the dedicated DNS method.
    Last edited by Nilpo; December 31st, 2013 at 02:31 PM.
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!

IMN logo majestic logo threadwatch logo seochat tools logo