Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

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

Options
  • 25-02-2016 9:07pm
    #1
    Registered Users Posts: 13,654 ✭✭✭✭


    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 Posts: 13,654 ✭✭✭✭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 Posts: 13,654 ✭✭✭✭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 Posts: 13,654 ✭✭✭✭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 Posts: 13,654 ✭✭✭✭mrcheez


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


  • Registered Users Posts: 13,654 ✭✭✭✭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 Posts: 13,654 ✭✭✭✭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 Posts: 13,654 ✭✭✭✭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 Posts: 13,654 ✭✭✭✭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