Subdomain to php file

Topics: User Forum
Oct 9, 2009 at 3:29 PM

Hi,

I just moved from Linux to Windows.  I have all subdomain traffic routed to the site root via dns, so anything.domain.com goes to domain.com.

I was using a .htaccess file to make it so that when someone entered anything.domain.com (except for www.domain.com) in their browser, they would get the page anything.php (contained in the site root).  The address bar didn't change, so this was a rewrite, not a redirect.  Here is the .htaccess file:

rewriteEngine on
rewriteCond %{HTTP_HOST} ^(.+)\.domain\.com [NC]
rewriteCond %{HTTP_HOST} !^www\.
rewriteCond %{REQUEST_URI} !^/images/.*
rewriteCond %{REQUEST_URI} !^/includes/.*
rewriteRule .* %1.php [L]

 

I've been struggling to get this to work with Ionic ISAPI rewrite, but no success so far.  Could you help me?

Thanks very much

 

Coordinator
Oct 10, 2009 at 6:35 PM
rewriteEngine on
rewriteCond %{HTTP_HOST} ^(.+)\.domain\.com [NC]
rewriteCond %{HTTP_HOST} ^(?!www\.)
rewriteCond %{REQUEST_URI} ^(?!/images/.*)
rewriteCond %{REQUEST_URI} ^(?!/includes/.*)
rewriteRule .* %1.php [L]
Oct 12, 2009 at 4:51 PM

Thank you.  Now when I visit about.domain.com in a browser, I get a 404 error.  A file called about.php is in the site root and I can view it using about.domain.com/about.php or domain.com/about.php.  I downloaded the log file and here is what it shows:

Mon Oct 12 11:44:37 - 98960 - LogFile re-opened.
Mon Oct 12 11:44:44 - 202060 - HttpFilterProc: SF_NOTIFY_URL_MAP
Mon Oct 12 11:44:44 - 202060 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
Mon Oct 12 11:44:44 - 202060 - DoRewrites
Mon Oct 12 11:44:44 - 202060 - DoRewrites: Url: '/'
Mon Oct 12 11:44:44 - 202060 - EvaluateRules: depth=0
Mon Oct 12 11:44:44 - 202060 - EvaluateRules: Rule 1 : -1 (No match)
Mon Oct 12 11:44:44 - 202060 - EvaluateRules: Rule 2 : 1 matches
Mon Oct 12 11:44:44 - 202060 - EvalCondition: ts1 'about.domain.com'
Mon Oct 12 11:44:44 - 202060 - ApplyCaseConversion: after  'about.domain.com'
Mon Oct 12 11:44:44 - 202060 - EvalCondition: checking 'about.domain.com' against pattern '^(.+)\.domain\.com'
Mon Oct 12 11:44:44 - 202060 - EvalCondition: match result: 2 (match)
Mon Oct 12 11:44:44 - 202060 - EvalCondition: ts1 'about.domain.com'
Mon Oct 12 11:44:44 - 202060 - ApplyCaseConversion: after  'about.domain.com'
Mon Oct 12 11:44:44 - 202060 - EvalCondition: checking 'about.domain.com' against pattern '^(?!www\.)'
Mon Oct 12 11:44:44 - 202060 - EvalCondition: match result: 1 (match)
Mon Oct 12 11:44:44 - 202060 - GetServerVariable: cannot find that variable
Mon Oct 12 11:44:44 - 202060 - EvalCondition: ts1 'REQUEST_URI'
Mon Oct 12 11:44:44 - 202060 - ApplyCaseConversion: after  'REQUEST_URI'
Mon Oct 12 11:44:44 - 202060 - EvalCondition: checking 'REQUEST_URI' against pattern '^(?!/images/.*)'
Mon Oct 12 11:44:44 - 202060 - EvalCondition: match result: 1 (match)
Mon Oct 12 11:44:44 - 202060 - GetServerVariable: cannot find that variable
Mon Oct 12 11:44:44 - 202060 - EvalCondition: ts1 'REQUEST_URI'
Mon Oct 12 11:44:44 - 202060 - ApplyCaseConversion: after  'REQUEST_URI'
Mon Oct 12 11:44:44 - 202060 - EvalCondition: checking 'REQUEST_URI' against pattern '^(?!/includes/.*)'
Mon Oct 12 11:44:44 - 202060 - EvalCondition: match result: 1 (match)
Mon Oct 12 11:44:44 - 202060 - EvalCondition: returning TRUE
Mon Oct 12 11:44:44 - 202060 - EvalCondition: returning TRUE
Mon Oct 12 11:44:44 - 202060 - EvalCondition: returning TRUE
Mon Oct 12 11:44:44 - 202060 - EvalCondition: returning TRUE
Mon Oct 12 11:44:44 - 202060 - EvalConditionList: rule 2, TRUE, Rule will apply
Mon Oct 12 11:44:44 - 202060 - ApplyCaseConversion: after  '.php'
Mon Oct 12 11:44:44 - 202060 - EvaluateRules: Result (length 4): .php
Mon Oct 12 11:44:44 - 202060 - EvaluateRules: Last Rule
Mon Oct 12 11:44:44 - 202060 - EvaluateRules: returning 1
Mon Oct 12 11:44:44 - 202060 - DoRewrites: Rewrite Url to: '.php'
Mon Oct 12 11:44:44 - 202060 - HttpFilterProc: SF_NOTIFY_URL_MAP

 

It looks like it matches, but then it looks for ".php" instead of "about.php".  Thanks again for you help.

Coordinator
Oct 12, 2009 at 9:46 PM

my mistake.

you havve to change the order of the rewritecond's to get it to work the way you expect.

rewriteEngine on
rewriteCond %{HTTP_HOST} ^(?!www\.)
rewriteCond %{REQUEST_URI} ^(?!/images/.*)
rewriteCond %{REQUEST_URI} ^(?!/includes/.*)
rewriteCond %{HTTP_HOST} ^(.+)\.domain\.com [NC]
rewriteRule .* %1.php [L]
Oct 13, 2009 at 12:41 AM

I really appreciate it.  About.php loads now.  Unfortunately, the images srcs and include file hrefs inside the page all get rewritten also.  That's what I was preventing in the .htaccess file with the lines that look for "/images/" and "/includes/".  I can get around this by using absolute URLs for all images and files, like http://domain.com/images/img_name.gif, so you've already solved my problem, but I 'm sure there's a way to do it with the filter, right?

Thanks again!

Coordinator
Oct 13, 2009 at 7:14 AM

Ah, yes I hadn't even looked at the server variables you are referencing.  You can see from the log that REQUEST_URI isn't resolving to anything.

I think, looking at the log file, you don't want REQUEST_URI but instead you want PATH_INFO .

 

Oct 14, 2009 at 3:36 PM

Thanks for that. I tried PATH_INFO.  I get the same result in the browser (images don't show up).  The log file output changed.  In this case, I went to jonathan.domain.com and got rewritten correctly to domain.com/jonathan.php.  Unfortunately, it seems that where it finds a match to "images" or "includes", it applies the rewrite to these too, so none of the images work.  Here is part of the log file:

Wed Oct 14 10:22:11 - 31972 - DoRewrites
Wed Oct 14 10:22:11 - 31972 - DoRewrites: Url: '/images/button_sub_previs_down.jpg'
Wed Oct 14 10:22:11 - 31972 - EvaluateRules: depth=0
Wed Oct 14 10:22:11 - 31972 - EvaluateRules: Rule 1 : -1 (No match)
Wed Oct 14 10:22:11 - 31972 - EvaluateRules: Rule 2 : 1 matches
Wed Oct 14 10:22:11 - 31972 - EvalCondition: ts1 'jonathan.domain.com'
Wed Oct 14 10:22:11 - 31972 - ApplyCaseConversion: after  'jonathan.domain.com'
Wed Oct 14 10:22:11 - 31972 - EvalCondition: checking 'jonathan.domain.com' against pattern '^(?!www\.)'
Wed Oct 14 10:22:11 - 31972 - EvalCondition: match result: 1 (match)
Wed Oct 14 10:22:11 - 31972 - EvalCondition: ts1 ''
Wed Oct 14 10:22:11 - 31972 - ApplyCaseConversion: after  ''
Wed Oct 14 10:22:11 - 31972 - EvalCondition: checking '' against pattern '^(?!images/.*)'
Wed Oct 14 10:22:11 - 31972 - EvalCondition: match result: 1 (match)
Wed Oct 14 10:22:11 - 31972 - EvalCondition: ts1 ''
Wed Oct 14 10:22:11 - 31972 - ApplyCaseConversion: after  ''
Wed Oct 14 10:22:11 - 31972 - EvalCondition: checking '' against pattern '^(?!includes.*)'
Wed Oct 14 10:22:11 - 31972 - EvalCondition: match result: 1 (match)
Wed Oct 14 10:22:11 - 31972 - EvalCondition: ts1 'jonathan.domain.com'
Wed Oct 14 10:22:11 - 31972 - ApplyCaseConversion: after  'jonathan.domain.com'
Wed Oct 14 10:22:11 - 31972 - EvalCondition: checking 'jonathan.domain.com' against pattern '^(.+)\.domain\.com'
Wed Oct 14 10:22:11 - 31972 - EvalCondition: match result: 2 (match)
Wed Oct 14 10:22:11 - 31972 - EvalCondition: returning TRUE
Wed Oct 14 10:22:11 - 31972 - EvalCondition: returning TRUE
Wed Oct 14 10:22:11 - 31972 - EvalCondition: returning TRUE
Wed Oct 14 10:22:11 - 31972 - EvalCondition: returning TRUE
Wed Oct 14 10:22:11 - 31972 - EvalConditionList: rule 2, TRUE, Rule will apply
Wed Oct 14 10:22:11 - 31972 - ApplyCaseConversion: after  '/jonathan.php'
Wed Oct 14 10:22:11 - 31972 - EvaluateRules: Result (length 13): /jonathan.php
Wed Oct 14 10:22:11 - 31972 - EvaluateRules: Last Rule
Wed Oct 14 10:22:11 - 31972 - EvaluateRules: returning 1
Wed Oct 14 10:22:11 - 31972 - DoRewrites: Rewrite Url to: '/jonathan.php'
Wed Oct 14 10:22:11 - 31972 - HttpFilterProc: SF_NOTIFY_URL_MAP
Wed Oct 14 10:22:11 - 31972 - HttpFilterProc: SF_NOTIFY_URL_MAP

Sorry to keep on with this, it just doesn't make sense!

Coordinator
Oct 14, 2009 at 6:39 PM

Try something else.

Try one of these:  REQUEST_FILENAME, URL

You'll have to keep testing.

Why is the value of PATH_INFO returning an empty string?  What are the values of the other server variables?  Figure this stuff out and you'll get it.