Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

ASP.NET - Redirecting wildcard sub-domain to folder (Plesk shared hosting)

  • 25-02-2016 09:07PM
    #1
    Registered Users, Registered Users 2 Posts: 14,401 ✭✭✭✭


    I've recently moved my site from a dedicated VM to a shared hosting environment as I didn't need to have a dedicated machine.

    The new environment has Odin Plesk 12, and most things are working fine except the wildcard redirect.

    So for example I want:
    test.mysite.com
    to go to
    www.mysite.com/member/test/

    On my old server I had the following in my web.config which worked fine:

    <rule name="my_subdomain" patternSyntax="ECMAScript" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{HTTP_HOST}" pattern="^(?!www)(\w+)\.mysite\.com$" />
    </conditions>
    <action type="Redirect" url="http://www.mysite.com/member/{C:1}/&quot; appendQueryString="false" redirectType="Permanent" />
    </rule>

    but getting a DNS lookup failure on the new server with the same web.config setting.

    I tried adding a .htaccess file to see if that would work, but to no avail.

    Any ideas?


    NOTE: Other rewritten urls are working fine, it's just the "www" replacement it can't handle.


Comments

  • Moderators, Society & Culture Moderators Posts: 17,642 Mod ✭✭✭✭Graham


    mrcheez wrote: »
    but getting a DNS lookup failure

    Have you checked your DNS and done an nslookup?


  • Registered Users, Registered Users 2 Posts: 14,401 ✭✭✭✭mrcheez


    Graham wrote: »
    Have you checked your DNS and done an nslookup?

    Actually I've got an update.. I changed the DNS settings so I have the following now:

    *.mysite.com (A record)
    mysite.com (A record)
    www.mysite.com (A record)

    As this is how the dedicated server was setup. The addition of *.mysite.com seems to have resolved the DNS error, but now I'm just getting a default Plesk homepage screen.

    When I ping blah.mysite.com I'm getting the correct IP address.


    www.mysite.com and mysite.com work fine.


  • Registered Users, Registered Users 2 Posts: 14,401 ✭✭✭✭mrcheez


    any ideas?


  • Moderators, Society & Culture Moderators Posts: 17,642 Mod ✭✭✭✭Graham


    Something like this:
    <rule name="CName to URL" stopProcessing="true">
        <match url=".*" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="^(?!www)(.*)\.domain\.com$" />
        </conditions>
        <action type="Redirect" url="http://domain.com/{C:1}/{R:0}" />
    </rule>
    

    More details here: http://weblogs.asp.net/owscott/url-rewrite-city-domain-com-to-domain-com-city


  • Registered Users, Registered Users 2 Posts: 14,401 ✭✭✭✭mrcheez


    Graham wrote: »
    Something like this:
    <rule name="CName to URL" stopProcessing="true">
        <match url=".*" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="^(?!www)(.*)\.domain\.com$" />
        </conditions>
        <action type="Redirect" url="http://domain.com/{C:1}/{R:0}" />
    </rule>
    

    More details here: http://weblogs.asp.net/owscott/url-rewrite-city-domain-com-to-domain-com-city


    hmm nope the subdomain is still just showing a Plesk homepage

    It must be something blocked by Plesk I guess.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 14,401 ✭✭✭✭mrcheez


    I see the rule is called CNAME to URL ... do I need to create a CNAME like "*.mysite.com" ?


  • Registered Users, Registered Users 2 Posts: 14,401 ✭✭✭✭mrcheez


    ok found out what's going on... it's a Plesk limitation for Windows only (predictably)

    Here's someone with the same issue and eventually found a solution by adding a wildcard subdomain.

    https://wordpress.org/support/topic/please-help-subdomain-blog-cannot-be-accessed-with-dns-a-wildcard


    But wildcard subdomains aren't allowed in Plesk for Windows. When I manually created a "test.mysite.com" subdomain it correctly redirected.

    Unfortunately I have about 5000 of these as each user on the site has their own subdomain, so I guess I'll have to change the code.


  • Moderators, Society & Culture Moderators Posts: 17,642 Mod ✭✭✭✭Graham


    Dump plesk


  • Registered Users, Registered Users 2 Posts: 14,401 ✭✭✭✭mrcheez


    Graham wrote: »
    Dump plesk

    You missed the part where I said it was shared hosting.. ain't got no choice and everything else on the server is working nicely :)

    I wonder if I can do it programmatically instead


  • Registered Users, Registered Users 2 Posts: 14,401 ✭✭✭✭mrcheez


    I checked the bindings I had on my old dedicated server for the site and they were:

    http - mysite.com - Port 80 - IP Address: *
    http - www.mysite.com - Port 80 - IP Address: *
    http - - Port 80 - IP Address: *

    I believe a sysadmin friend of mine set these up about 6 years ago, so is it possible that the 3rd "blank" entry is the solution I need to implement to get subdomain requests arriving to my site?

    At the moment blah.mysite.com isn't hitting my web.config


    I asked the new provider if they could make these changes in IIS for me, and they said yes, for a small fee, but I'd like to know if it will have the desired effect before I pay up!


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 14,401 ✭✭✭✭mrcheez


    anyone know if the 3rd binding I mentioned before is what I need to add to get wildcard subdomains working on my site?

    so it's:
    Type = http
    Host Name = {blank}
    Port = 80
    IP Address = *

    At the moment I have the "www" and "non-www" bindings.


Advertisement