They act as subdomains to my website. For the first 2, I simply want to first ensure that request is not directly requesting into the folders, and secondly, just serve up the file/folder if they exist, ie:
files.domain.com/folder (rewrites to) /files/folder (and if the folder exists, attempts to display its contents) files.domain.com/doc.txt (rewrites to) /files/doc.txt (and if the file exists, attempts to serve it to user)
but the user should NOT be able to request the subdomain folder directly like this:
And just to show I’m not blindly asking for help (I would LOVE if someone could explain their process to a solution) here is the (faulty) rules I have which so far are just leading me to a brick wall.
[FONT=courier new]RewriteEngine On
#These subdomains we just pass through…
RewriteCond %{HTTP_HOST} ^(files|framework)\. [NC]
RewriteCond %{REQUEST_URI} !^\/(files|framework) [NC]
RewriteRule ^(.*)$ \/%1%{REQUEST_URI} [R=301,L][/FONT]
I thought this would check if the subdomain host had “files.” or “framework.” in the beginning and then ensure that the requested URI does not begin with “/files” or “/framework” and if so, rewrite to (for example), “/files/doc.txt” But sure enough I’m just getting 500 server errors when I test it out.
Drop back ten and consider the DocumentRoot of these subdomains (each is treated as a completely separate domain although they can all be “parked” on the main domain - which your code indicates is what you’re trying to catch).
If you have files and framework created with their DocumentRoot being in those subdirectories of www (that should BE the main domain’s DocumentRoot), neither subdomain request can access the other and neither can access the www (main domain) DocumentRoot. I’d make my setup like this to avoid “sorting problems.”
That said, the subdomains will take care of themselves but it’s your domain/files or domain/framework which needs to be addressed by checking for those directories in the request (in the domain’s DocumentRoot .htaccess file) and, if found, redirect to the subdomain to handle the request:
RewriteEngine on
RewriteRule (files|framework)/(.*)$ http://$1.domain.com/$2 [R=301,L]
Hey DKLynn, thank you for taking the time to respond.
I am going to flesh out my inner thinking just so any holes in them can be filled in. First, I am actually on a Windows environment. We are using a tool in IIS7 that basically emulates 99% of the functionality of the Apache Mod Rewrite. The way I currently organize my projects is, that I make a new folder for each domain and immediately inside it are subfolders for the subdomains of that domain (with ‘www’ being where I put the default website in) So for example, my document root is:
[/B]In IIS I setup a website called “AaronMartoneCom” and it’s root goes only up to the folder with the same name. NORMALLY, I could call the different folder locations by links like “/www/file.txt” or “/files/private/stuff.doc”.
I made “bindings” to the site which indicate the list of host names that the site responds to. I added “www.aaronmartone.com”, “files.aaronmartone.com”, “framework.aaronmartone.com” and “aaronmartone.com”.So if I request any of those addresses, it basically requests the root of the site. I then use the rewriting to read the host, check for which “subdomain” it is requesting, and then rewrite accordingly so that requests like:
This is how my host explained that i could use URL rewrite to do subdomaining on my setup. Can I confirm with you that this is similar in process to what you are envisioning, or is this something entirely different?
The {IS_SUBREQ} will prevent looping on a redirection whereas the {HTTP_HOST} checks that the request is NOT to a subdomain.
Untested but either should work and it all depends upon what you’re really trying to do. Note, though, that {IS_SUBREQ} may be part of the “1% incompatible” that is claimed for the mod_rewrite-like code you’re using.
These sub-requests. I heard about them through other resources, and someone said they had to do with the looping nature of URL rewriting rules. Can you explain to me what a sub-request is and how it differs from a normal request?
As far as what you’ve listed there, I think I need to clarify something, because I got to speak with a co-worker who used to work in Apache (and I think things are done a little differently in regards to subdomains)
My host confirmed for me that the way they do subdomains on a 1-site account is:
Host’s DNS files resolve files.domain.com to point to IP address of the server that is hosting my site
IIS gets the request and looks at the host name “files.domain.com”.
IIS checks to see which of its sites have a binding that matches, my site has one setup, so it sends the request to that site
URL rewriting captures the request, let’s say it’s files.domain.com/folder/file.ext. At this point, we don’t want to do any redirecting BACK to files.domain.com (because we’re already there). Instead, it needs to just rewrite the request as /files/folder/file.ext (hopefully checking if that file exists, and if so then serving up the file)
This might be a very different process than how subdomains are done on Apache/Unix. If I had a plan that allowed me multiple sites in IIS (I don’t) then I could create a site for each subdomain, so that “www.domain.com” requests go to my “www.domain.com” site, “files.domain.com” go to my site setup for “files.domain.com”, etc. But since I don’t, he said the only way I can do subdomaining off 1 site is to redirect requests to subfolders off the root.
I hope that has clarified (I don’t fault you for hating on Windoze; the only 2 things from Microsoft I like are SQL Server and IIS7)
Now, with all that behind us, the second code set above appears to be what you’re after (to force the subdomain use for the files and frames subdirectories - which should not be accessible from the www subdomain/subdirectory).