Forum Moderators: phranque

Message Too Old, No Replies

subdomain and https problem

directory becomes visible

         

pixeltierra

1:05 am on Oct 24, 2006 (gmt 0)

10+ Year Member



I have a subdomain set up on my host and it behaves normally:

entering 'test.domain.com' as url resolves to:

[test.domain.com...]

which is really the file:

[domain.com...]

The 'test' directory when using the subdirectory becomes "transparent". However, when I set up https traffic with the following code something weird happens and makes the directory show:

RewriteEngine on
#Options +FollowSymlinks
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*) [%{HTTP_HOST}...] [R,L]

entering in 'http://test.domain.com' as a url resolves to:

[test.winbcms.org...]

The problem is that the tranparent directory (test) is no longer transparent, in a way defeating the purpose of the subdirectory.

Anyone know what this is for? Is it an error in my rewrite? All I really want to do with the re-write is make all page calls https instead of http. Is there a way to do this and use subdomains?

jdMorgan

1:40 am on Oct 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The answer all hinges on *how* you set up the subdomain, and *where* your https redirect code above is located.

If the subdomain is 'mapped' to the subdirectory in httpd.conf (manually or by using a control panel), and the redirect code shown above is located in .htaccess (or if it follows the subdomain/subdirectory rewrite in httpd.conf), then the (transparent) rewrite to the subdirectory will occur before the redirect code executes.

If that happens, the /test subdirectory will be exposed by the external redirect.

The key is to do both in the same file -- httpd.conf or .htaccess -- so that you can control the order in which the two functions execute. You want the external redirect to https to occur first, and then internally rewrite to /test later if required.

Jim

pixeltierra

2:23 am on Oct 24, 2006 (gmt 0)

10+ Year Member



ok JD:

I had to read your post like 10 times, but I think I understand what you're saying. The host (LP) says that the subdomain(s) has to propagate through their DNS servers.

I DID configure the subdomain via Control Panel. I'm on a shared server, so I don't have access to httpd.conf. And I DO want the subdirectory (/test) to be transparent.

If I understand what you're saying, I have to do them both in the same file, and I have to FIRST do the https rewrite and THEN "internally rewrite to /test".

The https rewrite is .htaccess, and the subdomain has something to do with the host DNS. The hosts allows stuff like email, stats and logs and whatnot for subdomains, just like regular domains, so I can't "fake it" with a simple directory rewrite. But maybe I can leave the subdomain configured like it is, then do the https rewrite (.htaccess), and then somehow make the /test directory disappear (also in .htaccess). Is that possible?

If not what is the ideal way to have https re-writes and use subdomains?

jdMorgan

3:23 am on Oct 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This has little to do with DNS. That's a separate issue from pointing a subdomain to a subdirectory, although it may be that your Control Panel implementation combines them and makes them inseparable. (A control panel is just a script that modifies the httpd.conf and/or conf.d file(s) in a way that the host considers 'safe' on a shared server. The only major problems with using Control Panels are that the code they write is inflexible and sometimes inefficient, and that the functions that you can implement with them are restricted, in the name of standardization/ease of verification and the safety of the other users sharing the server.)

Find out from your host if they can do the following, or if you can do it from the control panel they provide.

  • Leave the DNS zone file alone, so that your test subdomain will still resolve to your server.

  • Once the request is resolved to your server, have all requests for your domain -including all subdomains- 'pointed' to your main domain's directory (This is probably where the current setup is going wrong, because the subdomain is already rewritten to a subdirectory in httpd.conf, before your redirect code can run).

    Now that all domains and subdomains point to your main directory, you can put all the code into .htaccess in that directory, so that you can control the order of execution:


    # Enable mod_rewrite & the rewrite engine
    #Options +FollowSymlinks
    RewriteEngine on
    #
    # Externally redirect all non-https requests to https
    RewriteCond %{SERVER_PORT} ^80$
    RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
    #
    # Internally rewrite test subdomain requests to the /test subdirectory
    RewriteCond %{HTTP_HOST} ^test\.example\.com
    RewriteCond $1 !^test/
    RewriteRule (.*) /test/$1 [L]

    The only complexity here is the second RewriteCond in the second ruleset -- It's needed to prevent an 'infinite' rewrite loop in .htaccess context. It only allows the rewrite if the current URL-path has NOT already been rewritten to the /test subdirectory.

    I don't know anything about your specific server setup, so I can't guarantee that this will work. I'd advise a thorough discussion with your hosting provider as to whether it will work. It works well for me on my servers, but one thing we've learned repeatedly in this forum is that all hosts are set up differently...

    Jim

  • pixeltierra

    6:53 am on Oct 24, 2006 (gmt 0)

    10+ Year Member



    Thanks for your help and time on this Jim.

    I've tested your code, but it only works when the orig url is [test.domain.com,...] or in other words when the https rewrite rule is not kicked in.

    I'm in contact with the host and will let you know what happens.

    pixeltierra

    5:33 pm on Oct 24, 2006 (gmt 0)

    10+ Year Member



    Ok, back from the host this is what I get:

    The function with the rewrites and the order change of how the site will
    execute would take a wildcard DNS, which is not supported on the servers. I
    apologize for the inconvenience this is causing you. Here is a link that might
    provide some additional information on this issue:
    [photomatt.net...]

    I personally think they're full of crap. I guess I can live without real subdomain functionality and just to a url rewrite.

    I'll have several "subdomains":

    red.domain.com
    blue.domain.com
    green.domain.com

    that I want to point to:

    domain.com/red/
    domain.com/blue/
    domain.com/green/
    etc...

    I might need a hand doing the rule. Would the following work:

    RewriteCond %{SERVER_HOST} ^red.domain.com$
    RewriteRule ^(.*) [domain.com...] [L]

    RewriteCond %{SERVER_HOST} ^blue.domain.com$
    RewriteRule ^(.*) [domain.com...] [L]

    etc...

    I've been trying things but keep getting errors.

    pixeltierra

    5:42 pm on Oct 24, 2006 (gmt 0)

    10+ Year Member



    I've realized without creating real subdomains, I can't get blue.domain.com to resolve to my ip at all.

    I'm pretty discouraged at this point. Is there any way to get that darn directory to be transparent?

    jdMorgan

    7:18 pm on Oct 24, 2006 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Sorry, the solution is to get e 'real' hosting company...

    Too many fish in the sea to bother with that one, I'm afraid.

    Jim

    pixeltierra

    2:22 am on Oct 25, 2006 (gmt 0)

    10+ Year Member



    I still haven't solved my little problem. Thanks for your continued input.

    This problem shouldn't be that hard it seems.

    I just want my subdomain test.domain.com to access the directory /htdocs/test here:

    https://test.domain.com/

    instead of:

    https://test.domain.com/test

    In the event that this really doesn't work out with my host, what host would you recommend (sticky me).