Forum Moderators: phranque
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?
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
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?
Find out from your host if they can do the following, or if you can do it from the control panel they provide.
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]
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
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.
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.
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).