Redirecting a 404, not sure if this is possible.

Topics: User Forum
Aug 18, 2010 at 10:54 PM

Hi all,

I currently have a very simple setup with IIRF, just a subdomain to directory mapping.

# IterationLimit
#
# Specifies the limit of mapping iterations for a single URL request. The default is 8.
IterationLimit 10

# MaxMatchCount
#
# Specifies the maximum number of sub-expression matches to capture for a single pattern.
# The default is 10.
MaxMatchCount 10

RewriteEngine ON
StatusUrl /iirfStatus
RewriteLog .\iirf
RewriteLogLevel 5

# use * instead of % for back-references
CondSubstringBackrefFlag *

RewriteCond  %{HTTP_HOST}   ^([^\.]+)\.dev\.domain\.com$
RewriteCond  d:\hosting\webroot\*1  -d
RewriteRule  ^/(.*)$        /*1/$1                   [L]

This works perfectly. Now the thing I really want to do is (and I'm pretty sure it can't be done, but figured I need to ask), is I want to handle the 404. In IIS I can set it to a URL (which is currently /index.php) and I dynamically handle 404's, what I want to do it remap the 404 so it goes to each subdomains index.php in it's directory.

Say I go to http://test.dev.domain.com/ (and it works fine and I get the default index.php in the d:\hosting\webroot\test\ directory). Then I go to http://test.dev.domain.com/blah.php, this doesn't exist, the IIS 404 kicks in and loads up /index.php (from d:\hosting\webroot\) is it possible to use IIRF to remap the 404 so that it would remap the 404 to the index.php IN the subdomain/directory?

I hope that makes sense?

Cheers
Ad

Aug 19, 2010 at 5:09 AM
Edited Aug 19, 2010 at 5:50 AM

So a little bit of research and RTFM I nutted what I was after

RewriteEngine ON
#StatusUrl /iirfStatus
#RewriteLog  .\iirf.log
#RewriteLogLevel 5

# IterationLimit
#
# Specifies the limit of mapping iterations for a single URL request. The default is 8.
IterationLimit 10

# MaxMatchCount
#
# Specifies the maximum number of sub-expression matches to capture for a single pattern.
# The default is 10.
MaxMatchCount 10

# use * instead of % for back-references
CondSubstringBackrefFlag *

RewriteCond %{HTTP_HOST} ^([^\.]+)\.dev\.domain\.com$ [I]
RewriteCond d:\hosting\dev.domain.com.au\webroot\*1\$1 !-d [NC]
RewriteCond d:\hosting\dev.domain.com.au\webroot\*1\$1 !-f [NC]
RewriteRule ^(.*)$ /*1/index.php?404;http://%{HTTP_HOST}$1 [L]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.dev\.domain\.com$ [I]
RewriteCond d:\hosting\dev.domain.com.au\webroot\*1 -d
RewriteRule ^/(.*)$ /*1/$1 [U,I,L]

Aug 19, 2010 at 6:42 PM
AdStar wrote:

So a little bit of research and RTFM I nutted what I was after

 I hope you mean netted, but i also understand that finding the solution yourself is very exciting. =)

Aug 27, 2010 at 10:46 AM

So this has been working a treat until......

RewriteEngine ON

# IterationLimit
#
# Specifies the limit of mapping iterations for a single URL request. The default is 8.
IterationLimit 10

# MaxMatchCount
#
# Specifies the maximum number of sub-expression matches to capture for a single pattern.
# The default is 10.
MaxMatchCount 10

# use * instead of % for back-references
CondSubstringBackrefFlag *

RewriteCond %{HTTP_HOST} ^([^\.]+)\.dev\.eyemedia\.com\.au$ [I]
RewriteCond d:\hosting\dev.eyemedia.com.au\webroot\*1\$1 !-d [NC]
RewriteCond d:\hosting\dev.eyemedia.com.au\webroot\*1\$1 !-f [NC]
RewriteRule ^(.*)$ /*1/index.php?404;http://%{HTTP_HOST}$1 [L]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.dev\.eyemedia\.com\.au$ [I]
RewriteCond d:\hosting\dev.eyemedia.com.au\webroot\*1 -d
RewriteRule ^/(.*)$ /*1/$1 [U,I,L]

How do I handle Query_String stuff....

Fri Aug 27 20:37:28 -  2460 - EvalCondition: ts1 'd:\hosting\dev.domain.com\webroot\*1\$1'
Fri Aug 27 20:37:28 -  2460 - GenerateReplacementString: result 'd:\hosting\dev.domain.com\webroot\ulogd\/id_detail.php?id=6768&prot=TCP'
Fri Aug 27 20:37:28 -  2460 - EvalCondition: checking 'd:\hosting\dev.domain.com\webroot\ulogd\/id_detail.php?id=6768&prot=TCP' against pattern '!-f'
Fri Aug 27 20:37:28 -  2460 - EvalCondition: cond->SpecialConditionType= 'f'
Fri Aug 27 20:37:28 -  2460 - EvalCondition: Special: it is not a file

How do I clean it up so it just looks for the file id_detail.php removing the query_string stuff?


Fri Aug 27 20:37:28 -  2460 - -------------------------------------------------------
Fri Aug 27 20:37:28 -  2460 - Ionic ISAPI Rewriting Filter (IIRF) 2.0.1.15 RELEASE
Fri Aug 27 20:37:28 -  2460 - IIRF was built on: Dec  3 2009 11:49:15
Fri Aug 27 20:37:28 -  2460 - Cached: DLL_PROCESS_ATTACH
Fri Aug 27 20:37:28 -  2460 - Cached: Process ID: 2388
Fri Aug 27 20:37:28 -  2460 - Cached: DLL_PROCESS_ATTACH - complete
Fri Aug 27 20:37:28 -  2460 - Cached: GetFilterVersion
Fri Aug 27 20:37:28 -  2460 - GetLogFile: app:'/LM/W3SVC/1648900910/Root'  new log:'D:\hosting\dev.domain.com\webroot\iirf.log.2388.log'
Fri Aug 27 20:37:28 -  2460 - ReadSiteConfig: actual log file 'D:\hosting\dev.domain.com\webroot\iirf.log.2388.log'
Fri Aug 27 20:37:28 -  2460 - ReadSiteConfig: ini file: 'D:\hosting\dev.domain.com\webroot\Iirf.ini'
Fri Aug 27 20:37:28 -  2460 - ReadSiteConfig: ini file timestamp: 2010/08/27 20:37:25 AUS Eastern Standard Time
Fri Aug 27 20:37:28 -  2460 - ReadSiteConfig: line   4: LogLevel = 5
Fri Aug 27 20:37:28 -  2460 - ReadSiteConfig: pass 1
Fri Aug 27 20:37:28 -  2460 - ReadSiteConfig: line   9: IterationLimit 10
Fri Aug 27 20:37:28 -  2460 - ReadSiteConfig: line  15: MaxMatchCount 10
Fri Aug 27 20:37:28 -  2460 - ReadSiteConfig: line  18: CondSubstringBackrefFlag *
Fri Aug 27 20:37:28 -  2460 - ReadSiteConfig: setting CondSubstringBackrefFlag to '*'
Fri Aug 27 20:37:28 -  2460 - ReadSiteConfig: line  20: RewriteCond   %{HTTP_HOST}  ^([^\.]+)\.dev\.domain\.com$
Fri Aug 27 20:37:28 -  2460 - ParseCondModifierFlags: '[I]'
Fri Aug 27 20:37:28 -  2460 - ParseCondModifierFlags: token 'I'
Fri Aug 27 20:37:28 -  2460 - Cond: Case Insensitive match
Fri Aug 27 20:37:28 -  2460 - ReadSiteConfig: line  21: RewriteCond   d:\hosting\dev.domain.com\webroot\*1\$1  !-d
Fri Aug 27 20:37:28 -  2460 - ParseCondModifierFlags: '[NC]'
Fri Aug 27 20:37:28 -  2460 - ParseCondModifierFlags: token 'NC'
Fri Aug 27 20:37:28 -  2460 - Cond: Case Insensitive match
Fri Aug 27 20:37:28 -  2460 - ReadSiteConfig: line  22: RewriteCond   d:\hosting\dev.domain.com\webroot\*1\$1  !-f
Fri Aug 27 20:37:28 -  2460 - ParseCondModifierFlags: '[NC]'
Fri Aug 27 20:37:28 -  2460 - ParseCondModifierFlags: token 'NC'
Fri Aug 27 20:37:28 -  2460 - Cond: Case Insensitive match
Fri Aug 27 20:37:28 -  2460 - ReadSiteConfig: line  23: RewriteRule (rule 1)  '^(.*)$'  '/*1/index.php?404;http://%{HTTP_HOST}$1'      [L]
Fri Aug 27 20:37:28 -  2460 - ReadSiteConfig: not a duplicate rule...
Fri Aug 27 20:37:28 -  2460 - ParseRuleModifierFlags: '[L]'
Fri Aug 27 20:37:28 -  2460 - ParseRuleModifierFlags: token 'L'
Fri Aug 27 20:37:28 -  2460 - rule: Last
Fri Aug 27 20:37:28 -  2460 - ReadSiteConfig: line  25: RewriteCond   %{HTTP_HOST}  ^([^\.]+)\.dev\.domain\.com$
Fri Aug 27 20:37:28 -  2460 - ParseCondModifierFlags: '[I]'
Fri Aug 27 20:37:28 -  2460 - ParseCondModifierFlags: token 'I'
Fri Aug 27 20:37:28 -  2460 - Cond: Case Insensitive match
Fri Aug 27 20:37:28 -  2460 - ReadSiteConfig: line  26: RewriteCond   d:\hosting\dev.domain.com\webroot\*1  -d
Fri Aug 27 20:37:28 -  2460 - ReadSiteConfig: line  27: RewriteRule (rule 2)  '^/(.*)$'  '/*1/$1'  [U,I,L]
Fri Aug 27 20:37:28 -  2460 - ReadSiteConfig: not a duplicate rule...
Fri Aug 27 20:37:28 -  2460 - ParseRuleModifierFlags: '[U,I,L]'
Fri Aug 27 20:37:28 -  2460 - ParseRuleModifierFlags: token 'U'
Fri Aug 27 20:37:28 -  2460 - rule: Unmangle URLs
Fri Aug 27 20:37:28 -  2460 - ParseRuleModifierFlags: token 'I'
Fri Aug 27 20:37:28 -  2460 - rule: Case Insensitive match
Fri Aug 27 20:37:28 -  2460 - ParseRuleModifierFlags: token 'L'
Fri Aug 27 20:37:28 -  2460 - rule: Last
Fri Aug 27 20:37:28 -  2460 - ReadSiteConfig: Done reading, found 2 rules (0 errors, 0 warnings) on 31 lines
Fri Aug 27 20:37:28 -  2460 - GetSiteConfig: Obtain  site '/LM/W3SVC/1648900910/Root' (era=1) (rc=1) (Expired=0) (ptr=0x024CDAE0)...
Fri Aug 27 20:37:28 -  2460 - HttpFilterProc: SF_NOTIFY_URL_MAP
Fri Aug 27 20:37:28 -  2460 - HttpFilterProc: cfg= 0x024CDAE0
Fri Aug 27 20:37:28 -  2460 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
Fri Aug 27 20:37:28 -  2460 - DoRewrites
Fri Aug 27 20:37:28 -  2460 - GetServerVariable_AutoFree: getting 'url'
Fri Aug 27 20:37:28 -  2460 - GetServerVariable_AutoFree: 128 bytes
Fri Aug 27 20:37:28 -  2460 - GetServerVariable_AutoFree: result ''
Fri Aug 27 20:37:28 -  2460 - GetHeader_AutoFree: getting 'url'
Fri Aug 27 20:37:28 -  2460 - GetHeader_AutoFree: 32 bytes   ptr:0x02954560
Fri Aug 27 20:37:28 -  2460 - GetHeader_AutoFree: 'url' = '/id_detail.php?id=6768&prot=TCP'
Fri Aug 27 20:37:28 -  2460 - GetServerVariable_AutoFree: getting 'QUERY_STRING'
Fri Aug 27 20:37:28 -  2460 - GetServerVariable_AutoFree: 17 bytes
Fri Aug 27 20:37:28 -  2460 - GetServerVariable_AutoFree: result 'id=6768&prot=TCP'
Fri Aug 27 20:37:28 -  2460 - GetHeader_AutoFree: getting 'method'
Fri Aug 27 20:37:28 -  2460 - GetHeader_AutoFree: 4 bytes   ptr:0x02954670
Fri Aug 27 20:37:28 -  2460 - GetHeader_AutoFree: 'method' = 'GET'
Fri Aug 27 20:37:28 -  2460 - DoRewrites: New Url, before decoding: '/id_detail.php?id=6768&prot=TCP'
Fri Aug 27 20:37:28 -  2460 - DoRewrites: Url (no decoding): '/id_detail.php?id=6768&prot=TCP'
Fri Aug 27 20:37:28 -  2460 - EvaluateRules: depth=0
Fri Aug 27 20:37:28 -  2460 - EvaluateRules: Rule 1 : 2 matches
Fri Aug 27 20:37:28 -  2460 - GetServerVariable: getting 'HTTP_HOST'
Fri Aug 27 20:37:28 -  2460 - GetServerVariable: 26 bytes
Fri Aug 27 20:37:28 -  2460 - GetServerVariable: result 'ulogd.dev.domain.com'
Fri Aug 27 20:37:28 -  2460 - ReplaceServerVariables: VariableName='HTTP_HOST' Value='ulogd.dev.domain.com'
Fri Aug 27 20:37:28 -  2460 - ReplaceServerVariables: in='%{HTTP_HOST}' out='ulogd.dev.domain.com'
Fri Aug 27 20:37:28 -  2460 - EvalCondition: ts1 'ulogd.dev.domain.com'
Fri Aug 27 20:37:28 -  2460 - GenerateReplacementString: result 'ulogd.dev.domain.com'
Fri Aug 27 20:37:28 -  2460 - EvalCondition: checking 'ulogd.dev.domain.com' against pattern '^([^\.]+)\.dev\.domain\.com$'
Fri Aug 27 20:37:28 -  2460 - EvalCondition: match result: 2 (match)
Fri Aug 27 20:37:28 -  2460 - EvalCondition: Cond %{HTTP_HOST} ^([^\.]+)\.dev\.domain\.com$ => TRUE
Fri Aug 27 20:37:28 -  2460 - EvalCondition: Child is non NULL (parent= 0x01C27BC0) (child= 0x01C27B88)
Fri Aug 27 20:37:28 -  2460 - EvalCondition: Current condition evaluates to TRUE
Fri Aug 27 20:37:28 -  2460 - EvalCondition: Logical AND, ergo we evaluate the Child
Fri Aug 27 20:37:28 -  2460 - ReplaceServerVariables: in='d:\hosting\dev.domain.com\webroot\*1\$1' out='d:\hosting\dev.domain.com\webroot\*1\$1'
Fri Aug 27 20:37:28 -  2460 - EvalCondition: ts1 'd:\hosting\dev.domain.com\webroot\*1\$1'
Fri Aug 27 20:37:28 -  2460 - GenerateReplacementString: result 'd:\hosting\dev.domain.com\webroot\ulogd\/id_detail.php?id=6768&prot=TCP'
Fri Aug 27 20:37:28 -  2460 - EvalCondition: checking 'd:\hosting\dev.domain.com\webroot\ulogd\/id_detail.php?id=6768&prot=TCP' against pattern '!-d'
Fri Aug 27 20:37:28 -  2460 - EvalCondition: cond->SpecialConditionType= 'd'
Fri Aug 27 20:37:28 -  2460 - EvalCondition: Special: it is not a directory
Fri Aug 27 20:37:28 -  2460 - EvalCondition: Special, retVal= false
Fri Aug 27 20:37:28 -  2460 - EvalCondition: Cond d:\hosting\dev.domain.com\webroot\*1\$1 !-d => TRUE
Fri Aug 27 20:37:28 -  2460 - EvalCondition: Child is non NULL (parent= 0x01C27B88) (child= 0x01C27B50)
Fri Aug 27 20:37:28 -  2460 - EvalCondition: Current condition evaluates to TRUE
Fri Aug 27 20:37:28 -  2460 - EvalCondition: Logical AND, ergo we evaluate the Child
Fri Aug 27 20:37:28 -  2460 - ReplaceServerVariables: in='d:\hosting\dev.domain.com\webroot\*1\$1' out='d:\hosting\dev.domain.com\webroot\*1\$1'
Fri Aug 27 20:37:28 -  2460 - EvalCondition: ts1 'd:\hosting\dev.domain.com\webroot\*1\$1'
Fri Aug 27 20:37:28 -  2460 - GenerateReplacementString: result 'd:\hosting\dev.domain.com\webroot\ulogd\/id_detail.php?id=6768&prot=TCP'
Fri Aug 27 20:37:28 -  2460 - EvalCondition: checking 'd:\hosting\dev.domain.com\webroot\ulogd\/id_detail.php?id=6768&prot=TCP' against pattern '!-f'
Fri Aug 27 20:37:28 -  2460 - EvalCondition: cond->SpecialConditionType= 'f'
Fri Aug 27 20:37:28 -  2460 - EvalCondition: Special: it is not a file
Fri Aug 27 20:37:28 -  2460 - EvalCondition: Special, retVal= false
Fri Aug 27 20:37:28 -  2460 - EvalCondition: Cond d:\hosting\dev.domain.com\webroot\*1\$1 !-f => TRUE
Fri Aug 27 20:37:28 -  2460 - EvalConditionList: rule 1, TRUE, Rule will apply
Fri Aug 27 20:37:28 -  2460 - GetServerVariable: getting 'HTTP_HOST'
Fri Aug 27 20:37:28 -  2460 - GetServerVariable: 26 bytes
Fri Aug 27 20:37:28 -  2460 - GetServerVariable: result 'ulogd.dev.domain.com'
Fri Aug 27 20:37:28 -  2460 - ReplaceServerVariables: VariableName='HTTP_HOST' Value='ulogd.dev.domain.com'
Fri Aug 27 20:37:28 -  2460 - ReplaceServerVariables: in='/*1/index.php?404;http://%{HTTP_HOST}$1' out='/*1/index.php?404;http://ulogd.dev.domain.com$1'
Fri Aug 27 20:37:28 -  2460 - GenerateReplacementString: result '/ulogd/index.php?404;http://ulogd.dev.domain.com/id_detail.php?id=6768&prot=TCP'
Fri Aug 27 20:37:28 -  2460 - EvaluateRules: Result (length 84): /ulogd/index.php?404;http://ulogd.dev.domain.com/id_detail.php?id=6768&prot=TCP
Fri Aug 27 20:37:28 -  2460 - EvaluateRules: Last Rule
Fri Aug 27 20:37:28 -  2460 - EvaluateRules: returning 1
Fri Aug 27 20:37:28 -  2460 - DoRewrites: Rewrite Url to: '/ulogd/index.php?404;http://ulogd.dev.domain.com/id_detail.php?id=6768&prot=TCP'
Fri Aug 27 20:37:28 -  2460 - HttpFilterProc: SF_NOTIFY_URL_MAP
Fri Aug 27 20:37:28 -  2460 - HttpFilterProc: cfg= 0x024CDAE0
Fri Aug 27 20:37:28 -  2460 - HttpFilterProc: SF_NOTIFY_URL_MAP
Fri Aug 27 20:37:28 -  2460 - HttpFilterProc: cfg= 0x024CDAE0
Fri Aug 27 20:37:28 -  2460 - HttpFilterProc: SF_NOTIFY_URL_MAP
Fri Aug 27 20:37:28 -  2460 - HttpFilterProc: cfg= 0x024CDAE0
Fri Aug 27 20:37:28 -  2460 - HttpFilterProc: SF_NOTIFY_URL_MAP
Fri Aug 27 20:37:28 -  2460 - HttpFilterProc: cfg= 0x024CDAE0
Fri Aug 27 20:37:28 -  2460 - HttpFilterProc: SF_NOTIFY_URL_MAP
Fri Aug 27 20:37:28 -  2460 - HttpFilterProc: cfg= 0x024CDAE0
Fri Aug 27 20:37:28 -  2968 - HttpFilterProc: SF_NOTIFY_LOG


Coordinator
Aug 30, 2010 at 11:20 PM
I think your question is a pretty basic one, but I can't tell just what you Are asking. I think you have a question about regex matching, but not sure. Maybe you are instead asking about rule evaluation order. I might be able to help of you post more English description of what you want and less log info, which isn't helpful in this case, at least not yet. You might also want to reread the documentation on RewriteRule, which has lots of regex examples.