How to get the rules to rewrite according to the db records?

Oct 30, 2008 at 4:09 AM
Edited Oct 31, 2008 at 12:19 PM
Hello,Cheeso
How to rewrite with records of the database to achieve the domain of the directory and binding
IIRF support through access with the MSSQL get rewrite rules?

For example:

Database Records

HTTP_HOST                           directory
www.codeplex.com     -->       /codeplex/index.html
www.code.com           -->       /codeplex/index.html
www.google.com         -->       /google/index.html
www.google.cn            -->       /google/index.html
www.google.net           -->       /google/index.html
www.microsoft.com     -->       /msdn/index.html
www.bbc.com              -->      /enbbc/index.html
......
Coordinator
Oct 30, 2008 at 9:20 PM
I am able to read the words you have written, but I am not able to make sense of them.
As a result, I have no idea what you want.
Can you please elaborate or ask your question a different way? 
Oct 31, 2008 at 11:36 AM
Edited Oct 31, 2008 at 12:53 PM
Whether the IIRF can  support to read the rewriting rules from the database,and how? For example, I have a set of records, which have the field of "domain" and "folder". "www.codeplex.com" and "/ codeplex" are respectively the strings of the two fields.
When the server receives the HTTP head of "www.codeplex.com"
(For example: select folder from tablestring where domain='www.codeplex.com'),
 it will rewrite the URL to the default document under the"/codeplex/index.html". 

Code way:
-----------------------------------------------------------------------------------
RewriteLog c:\iirfLog.out
RewriteLogLevel 0

#Database is MSSQL

SQLHost=(local)
SQLDatabaseName=IIRF
SQLUserName=sa
SQLPassword=abcd

RewriteCond %{HTTP_HOST} ^.*\.[^google]\.[^cn]$ [I]
SQLExecute(select dir,folder from Url_Rules where domain = '%1')
RewriteRule  ^(.*)$  /$1/$2/$3 [L]
-----------------------------------------------------------------------------------
   ^
$1 = Rs("dir")
$2 = Rs("folder")
$3 = (.*)

Thanks!
Coordinator
Oct 31, 2008 at 5:19 PM
Edited Nov 2, 2008 at 5:02 AM
Ok, thank you for the clarification.
No, IIRF gets the rules and configuration from the ini file.
If you have rules in a database, I could imagine producing a trigger that executes when the rules table is updated. The trigger would then write out a fresh ini file, which would then be read by IIRF.
You would have to write the trigger.
If you do not expect the rules to change very often, then the logic to generate the ini file need not be a trigger. It could just be a Stored Procedure, or a script, that you run periodically from the Windows Task Scheduler.
Coordinator
Oct 31, 2008 at 5:40 PM
Edited Nov 2, 2008 at 5:01 AM
or just run the script manually, whenever necessary.
Oct 31, 2008 at 6:20 PM
Edited Oct 31, 2008 at 6:32 PM
OK,Thank you!
But the rules to change very often.
Can you add regular expressions to the script of support?
I think that the rules will be very flexible.
For example: 
ini file

RewriteCond %{HTTP_HOST} ^.*\.[^codeplex]\.[^com]$ [I]
SQLExecute(select dir,folder from Url_Rules where domain = '%1')
RewriteRule  ^(.*)$  /$1/$2/$3 [L]

MS-SQL records
Url_domain
domain dir folder
www.google.cn a google
www.google.com a google
www.google.net a google
www.google.gov a google
www.search.com a google
......

Results:
www.google.cn/index.htm  -->  /a/google/index.htm
www.google.com/index.htm  -->  /a/google/index.htm
www.google.net/index.htm  -->  /a/google/index.htm
www.google.gov/index.htm  -->  /a/google/index.htm
www.search.com/index.htm  -->  /a/google/index.htm
www.search.com/index.php  -->  /a/google/index.php
......

I hope you can help me, thanks very much!
Coordinator
Oct 31, 2008 at 6:50 PM
Edited Nov 2, 2008 at 5:00 AM
You asked:
You can add regular expressions to the script of support?
I'm sorry. Once again, I don't understand what you are asking. IIRF already supports regular expressions.
----
Maybe you have not understood what I wrote?
I am suggesting that YOU can write a script to generate the ini file from the database contents.
If you are asking if I can enhance IIRF to read rules from the database - no, I cannot do that.
That would be a major undertaking, a significant design effort, and would require lots of testing required to make it work.
It would significantly expand the footprint of IIRF and would introduce reliability risks. This is beyond the scope of something I could do.
Writing a script to retrieve information from a database and then emit an ini file - that seems much simpler and easier.
Why don't you try that?
Nov 1, 2008 at 5:41 AM
I'm sorry Cheeso,my English is too bad!
but thank you to your help.
I think so,Writing a script to retrieve information from a database,It is not be able to meet.
Because the ini file,it is will be very very long, and logic will be Complex.
IIRF is a great project!
Thanks!
Coordinator
Nov 4, 2008 at 5:37 PM
Thanks for the comment, sorry I couldn't be of more help. Good luck!
Aug 28, 2009 at 12:16 AM

i've gone down the path of dynamically writing the .ini file whenever changes occur- within our CMS- and have found it to work very well.

simple database query to get list of pages, run through pages and apply rule to each, then save the ini file.

doesnt even need a site restart.

great little app btw cheeso