Hey dklynn, thanks for the response, let me see if I can clarify a little more.
I need this script to support running on my local copy of IIS7/Win7x64 as well as the host (who is running IIS7/Server2008) This is the URL Rewrite mod they support. So hopefully I can get a rewrite written that’ll work on both locations, what I call development and production.
The structure I’m looking for on production is:
(a).(b).(c)(/d) ie www.aaronmartone.com/this/that
You’re looking at the URL and capturing the (optional) subdomain, domain, top level domain (tld) and URI. The two versions of Apache have a problem with the URI as Apache 1.x REQUIRES its regex to match the leading / while Apache 2.x (a) will NOT match a leading / in the regex but (b) will insert it in a redirection with the {REQUEST_URI} variable. It’s confusing but you need to know which version of Apache M$ is trying to imitate.
a = “www”, but the script needs to support someone specifying NO subdomain either.
b = “aaronmartone”, the domain name
c = “com” the tld
d = everything after the tld, including the “/”.
On localhost, the server is localhost, but I use DNS mappings so that I can create entries like:
DNS mappings? Okay, I’ll treat that like a VirtualHost in Apache and ask whether each subdomain’s DocumentRoot is shared with the main domain or points to a specific location in your file structure (development should match production if at all possible else your rewrite code will necessarily be different which defeats the reason to use a development server).
aaronmartonecom.localhost 127.0.0.1
acp.aaronmartonecom.localhost 127.0.0.1
www.aaronmartonecom.localhost 127.0.0.1
KUDOS to you for understanding that you can use localhost as the tld for local domains! That will make life much easier for you.
Basically it’s so my computer doesn’t go out to the net and try to lookup these addresses; they stay and reside on localhost.
OK. Now, the first part is the subdomain. The acceptable values I want are: acp, clients, files, images, secure and www. BUT they can also provide NOTHING (remember this for later) If they DO provide a subdomain, I only want to group catch the characters, not the following “.” separating it between the domain name.
Then, the domain. I was using [a-z0-9\-] because the only acceptable characters I want in my domains are a-z, 0-9 and hyphens. I also need this value to be captured, not so important on production environments, but in development, it lets me know which project I’m working on.
Preferably, use [-a-z0-9]+ rather than incorrectly trying to escape the hyphen in the character range definition. That said, it looked like your domain was “aaronmartonecom” but … that’s for another day, I guess.
Next, the tld (on production, acceptable ones: com, net, org) or “localhost” if on development.
:tup:
Lastly, anything that comes after this. Am I right in saying that www.domain.com is the value of the [HTTP_HOST] variable?
{HTTP_HOST}, yes!
So for production it would take:
files.aaronmartone.com/this/that and convert it to: /files/index.cfm?$ses=/this/that
[indent]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^((acp|clients|files|images|secure|www)\\.)?([-a-z0-9]+)\\.(com|net|org) [NC]
RewriteCond %{REQUEST_URI} !^(acp|clients|files|images|secure|www)/
RewriteRule .? %1index.cfm?\\$ses=%{REQUEST_URI} [L]
The first RewriteCond captures the parts of the {HTTP_HOST} as requested and the second RewriteCond is there to prevent looping on the subdomain values IF rewritten to the subdirectory (this assumes that the subdomain shares the DocumentRoot with the main domain). The RewriteRule performs the redirection but I’m concerned with the $ of the key (which I’ve escaped because this character is normally not allowed in a URL - see http://www.ietf.org/rfc/rfc2396.txt).[/indent]
On development:
clients.aaronmartonecom.localhost/this/that converts to: /projects/aaronmartonecom/clients/index.cfm?$ses=/this/that
RewriteCond %{HTTP_HOST} ^((acp|clients|files|images|secure|www)\\.)?([-a-z0-9]+)\\.(localhost) [NC]
RewriteCond %{REQUEST_URI} !^(acp|clients|files|images|secure|www)/
RewriteRule .? /projects/%3/%2/index.cfm?\\$ses=%{REQUEST_URI} [L]
project-name.localhost/this/that converts to: /projects/project-name/www/index.cfm?$ses=/this/that (see how no subdomain points to www by default?)
RewriteCond %{HTTP_HOST} ^((acp|clients|files|images|secure|www)\\.)?([-a-z0-9]+)\\.(localhost) [NC]
RewriteCond %1 =""
RewriteCond %{REQUEST_URI} !^(acp|clients|files|images|secure|www)/
RewriteRule .? /projects/%2/www/index.cfm?\\$ses=%{REQUEST_URI} [L]
See, this is why I needed to catch “aaronmartonecom”, because my directory structure has the project names as folders in it, so for things to work locally, from the root of the server it has to get to:
c:\inetpub\wwwroot\projects\aaronmartonecom\www\index.cfm
[URL=“http://www.aaronmartonecom.localhost/this/that”]clients.aaronmartonecom.localhost/this/that converts to: /projects/aaronmartonecom/clients/index.cfm?$ses=/this/that
project-name.localhost/this/that converts to: /projects/project-name/www/index.cfm?$ses=/this/that (see how no subdomain points to www by default?)
See, this is why I needed to catch “aaronmartonecom”, because my directory structure has the project names as folders in it, so for things to work locally, from the root of the server it has to get to:
c:\inetpub\wwwroot\projects\aaronmartonecom\www\index.cfm
Has this cleared up anything? (Hope so, I’m new to RegEx, and it’s really greek to me) I had a friend helping me at work, but the day’s over and I won’t see him til next monday! Thanks for the assistance.