Almost there! Need a wee bit o' assistance with RegEx

Gonna make this as short n sweet as possible:

Can anyone help me?

I thought to start off as:

RewriteCond %{HTTP_HOST} ([a-z0-9\\-]+)\\.(aaronmartonecom|aaronmartone\\.com) [NC]
RewriteRule ^(.*)$ \\/%1\\/index\\.cfm?ses=%{REQUEST_URI} [NC,L]

But it doesn’t seem to be doing it…

Hi Aaron!

Let me boil this down for you: You have two subdomains (www and files) that you’re concerned with as well as two domains (one local, one production - you don’t have others in this physical directory, do you?). Your problem is to pass through the files subdomain and redirect the www subdomain (you’re not worried about the lack of both?).

[*]On localhost, requests to www subdomain are rewritten from: http://www.aaronmartonecom/this/that to: /www/index.cfm?ses=/this/that

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\\. [NC]
RewriteRule ^([a-z]+/[a-z]+)$ index.cfm?ses=/$1 [L]

Note, please, that I assumed that your www directory is the location of your “webspace,” thus, I did not include that path to index.cfm - add it back if I’m incorrect.

If I was incorrect about only two domains sharing this physical location, then you can complete the RewriteCond by adding aaronmartone\.?com after the www\., i.e., RewriteCond %{HTTP_HOST} ^www\.aaronmartone\.?com$ [NC] so that the dot in the dot com is optional (the POWER of regex).

Regards,

DK

Hey dkLynn - That’s correct. 2 subdomains for each of 2 domains. And with what you’ve said, you’ve proven I made a mistake in my original post.

It seems the FILES subdomain DOES need rewriting as well! In the root of my website there are 2 folders, FILES and WWW. Requests to the FILES subdomain would also need to be rewritten BUT they would be served directly up to the user, ie:

http://files.aaronmartonecom/pdfs/file.pdf should redirect (from the root of the site) to /files/pdfs/file.pdf

http://www.aaronmartonecom/this/that should redirect (from the root of the site) to /www/index.cfm?ses=/this/that (at which point Coldfusion will handle building the page)

It’s just that after the rewrite is done, the file needs to be served up to the user as if they called it directly.

I tried code you provided and so far that worked perfect for www calls IF I changed one thing; let me see if I have this:

RewriteCond %{HTTP_HOST} ^www\\. [NC]

This says “If the host begins with “www” and we are ignoring case…”

RewriteRule ^([a-z]+/[a-z]+)$ index.cfm?ses=/$1 [L]

This says we rewrite (what?) to index.cfm?ses/(matched criteria) and that this is the last rule to perform.

I changed this last rule to www/index.cfm?ses=/$1 and the file came up like expected (the root of the website contains the ‘www’ folder, and in there is the index.cfm file.

This is a great start. A couple questions if I may.

  1. How would we modify the rule so that requests to the files directory would goto: /files/(path provided)?

  2. I see a lot of people doing the following with their rules:


RewriteCond %{REQUEST_URI} !-d
RewriteCond %{REQUEST_URI} !-f

I think this means “ensure the user is not directly requesting a file or directory that exists as well” Am I right? Is this something we need as well.

The files folder allows for directory browsing BUT is it possible to keep the person from directly requesting the file like:

http://aaronmartone.com/files/pdfs/file.pdf by ensuring they go through:

http://files.aaronmartone.com/pdfs/file.pdf ?

I’m glad to see the www redirect working so far. I guess one of my major concerns here was that in 100% of the examples I was shown, people always talked about rewriting AFTER the user requested an actual file, ie:

requests:
www.domain.com/file.cfm?this=that&that=this
rewritten as:
www.domain.com/file/that/this

But for me, anyone requesting from the www subdomain won’t ever be requesting a file directly (like www.aaronmartone.com/file.cfm) but instead is requesting a location that doesn’t even exist (like [URL=“http://www.aaronmartone.com/blog”]www.aaronmartone.com/blog)

I’ve seen a couple people address this (I think) by making a RewriteCond where they ensure the REQUEST_URI does not begin with the subdomain folder, ie:

people shouldn’t be able to call: aaronmartone.com/www/etc
instead they should call: www.aaronmartone.com/etc

people shouldn’t be able to call: aaronmartone.com/files/etc
instead they should call: files.aaronmartone.com/etc

So do we need to add that to this redirect rule as well?

Also, I like how you did that aaronmartone\?.com reference. Nice! That will handle both “aaronmartonecom” for local calls and “aaronmartone.com” for remote ones. Very smooth.

Hi Aaron,

Oh, no!

Okay, that’s just a minor problem as it’ll take two RewriteRules … but let me go through your response (questions) first.

TWO subdirectories, one for each subdomain. Wouldn’t it be easier to have the subdomains merely pointing to their respective subdirectories (for their DocumentRoot)? Okay, that’s NOT your question, only the way that I’d REDEFINE the problem (with a differrent solution). It’s clear that you’ve “parked” the subdomains ON the main domain’s DocumentRoot so that’s what we’ll work with here.

IF you don’t use R=301 redirects or external (absolute) redirects, you’ll leave the location box alone so that it’ll appear that your file resides elsewhere.

Regards,

DK

OK! Good/Bad News


RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\\.aaronmartone\\.?com$ [NC]
RewriteRule .? /www/index.cfm?\\$ses=%{REQUEST_URI} [L]

RewriteCond %{HTTP_HOST} ^files\\.aaronmartone\\.?com$ [NC]
RewriteRule .? /files%{REQUEST_URI} [L]

With this code, the first redirects (for the www subdomain) are working FLAWLESSLY.

I put an index.cfm file in there which dumps out the query string and going to: http://www.aaronmartonecom/this/that took me to the page which stated “This is the index file in the www folder off the root and the querystring is: /this/that”

Perfect!

But my files redirect isn’t working (and this probably is because I’m not doing something which passes through the request to just be served up. So if we could get that one working I think I’ll be set.

Right now, going to files.aaronmartonecom/public/pdfs/file.pdf just reports back in the browser:


[B]Error 404.0[/B]
Requested URL : http://files.aaronmartonecom:80/files/files/public/pdfs/file.pdf
Physical Path : c:\\inetpub\\wwwroot\\aaronmartonecom\\files\\files\\public\\pdfs\\file.pdf

(Not sure how this “files/files” is coming about) Also, though IIS shows port 80, that’s not in my actual URL request, I think IIS just internally appends it because that’s the port it’s running off of.

Uh, oh!

IIS? In the Apache forum board? HORRORS! :eek2: While M$ has attempted to imitate Apache’s mod_rewrite, reports are that they have not been completely successful.

Now, if you’re using port 80 for a URL, then you’ll need to redirect any external redirect to the same port (80 is the default so you don’t need that).

As far as passing through “something” to fetch the file, that’s EXACTLY what the %{REQUEST_URI} string is doing.

The problem appears to be the disconnect between the “specification” (starting a files request with files) and your test URI: files.aaronmartonecom/public/pdfs/file.pdf. It’s important to get the spec right before getting to coding.

Regards,

DK

Well I know that with IIS I can call:

http://localhost/folder/file.cfm (no port specified) and it’ll work fine on the front end. I’m not running any sites on ports other than 80 on the local machine.

Well, right now, the www redirect is working, and that’s what was holding me up, so I can go forward because that’s working as expected; I just gotta figure this files redirect out later.