Best Practices for Using IIRF?

Topics: Developer Forum
Mar 11, 2010 at 1:37 PM

Hello again,

I was wondering about best practices for using IIRF. I want to structure my file so that it has as small a footprint as possible. The main tasks I am hoping to accomplish are:

1: 301 redirect old page names with underscores to pages with hyphens
2: rewrite URL to call a server-side component to serve out content from db
3: prepend www to any url that is missing it

Because of my limited experience with url rewriting and regex I've mashed together a .ini but I really have no idea of it's even a good way to do any of this.

Here's my files:

# IIRF.ini
#

RewriteLog D:\inetpub\ISAPI_Rewriter.Log\rewriteLog1.out 
RewriteLogLevel 0
IterationLimit 10
MaxMatchCount 10
RewriteEngine ON
StatusInquiry ON

# Define Rewrite Maps

# Map takes the file name in and outs the same filename lowercase with dashes instead of underscores.
RewriteMap auto301 txt:D:\inetpub\globalFunctions\IIRF-Maps\Auto-Racing-301-Map.txt 
   
# Map takes the lowercase with dashed url and matches it to a call to page serve component
RewriteMap automap txt:D:\inetpub\globalFunctions\IIRF-Maps\Auto-Racing-Rewrite-Map.txt

# Apply permanent redirection maps - this is just for one category, there are dozens of categories to do
RedirectRule ^/Auto_Racing/(.*) /auto-racing/${auto301:$1|auto-racing.cfm} [R=301,I]

# Apply rewrite maps to call cfc - this is just for one category, there are dozens of categories to do
RewriteRule ^/auto-racing/(.*) ${automap:$1|/globalFunctions/parsePage.cfc?method=returnPage&category=Auto%20Racing&PageID=240} [I]

# Add www to secure calls to domain
RewriteCond %{HTTP_HOST} ^domainname.com [I]
RewriteCond %{HTTPS} on
RedirectRule ^(.*)$ https://www.domainname.com$1 [R=301]

# Add www to non-secure calls to domain.
RewriteCond %{HTTP_HOST} ^domainname.com [I]
RewriteCond %{HTTPS} off
RedirectRule ^(.*)$ http://www.domainname.com$1 [R=301]

# END OF .ini

-------------------------------------------------------------------------------------------------------

# Start Auto Racing 301 Redirect Map - This is only a few examples, actual map has hundreds 
# I'm sure this could be done without a map file, I just don't know how to do string replace.

C.A.R.T..cfm      c.a.r.t..html
Formula_One.cfm     formula-one.html
Formula_One_Australian_Grand_Prix_Tickets.cfm     formula-one-australian-grand-prix-tickets.html
Formula_One_Belgium_Grand_Prix_Tickets.cfm     formula-one-belgium-grand-prix-tickets.html
Formula_One_Brazilian_Grand_Prix_Tickets.cfm     formula-one-brazilian-grand-prix-tickets.html
Formula_One_British_Grand_Prix_Tickets.cfm     formula-one-british-grand-prix-tickets.html
Formula_One_Canadian_Grand_Prix_Tickets.cfm     formula-one-canadian-grand-prix-tickets.html
Le_Mans.cfm     le-mans.html

-------------------------------------------------------------------------------------------------------

 # Start Auto Racing URL Rewrite Map - This is only a few examples, actual map has hundreds

c.a.r.t..html     /globalFunctions/parsePage.cfc?method=returnPage&category=Auto%20Racing&PageID=701
formula-one.html     /globalFunctions/parsePage.cfc?method=returnPage&category=Auto%20Racing&PageID=699
formula-one-australian-grand-prix-tickets.html     /globalFunctions/parsePage.cfc?method=returnPage&category=Auto%20Racing&PageID=585
formula-one-belgium-grand-prix-tickets.html     /globalFunctions/parsePage.cfc?method=returnPage&category=Auto%20Racing&PageID=598
formula-one-brazilian-grand-prix-tickets.html     /globalFunctions/parsePage.cfc?method=returnPage&category=Auto%20Racing&PageID=602
formula-one-british-grand-prix-tickets.html     /globalFunctions/parsePage.cfc?method=returnPage&category=Auto%20Racing&PageID=594
formula-one-canadian-grand-prix-tickets.html     /globalFunctions/parsePage.cfc?method=returnPage&category=Auto%20Racing&PageID=592
le-mans-classic-tickets.html     /globalFunctions/parsePage.cfc?method=returnPage&category=Auto%20Racing&PageID=607

-------------------------------------------------------------------------------------------------------

 

Thanks for any advice.

Coordinator
Mar 11, 2010 at 11:04 PM

Hi Modus,

Your ini looks good.

Some comments. It's possible to transpose all underscores to dashes, without a map.   You would use something like this:

## =======================================================
## Phase 1 - 301 redirect any URL with an underscore
## =======================================================
  # two or more underscores remain - rewrite and loop around
  RewriteRule ^/(.*)_(.*)_(.*)$    /$1_$2-$3

  # last underscore - redirect (301) to down-cased URL (also swap .cfm for .html)
  RedirectRule ^/(.*)_(.*)\.cfm$    /#L$1-$2#E.html      [R=301]
## =======================================================

That may or may not be something you want. The result will be that any URL with underscores will get redirected, even if it is a bogus URL.  In that case, the browser will eventually get a 404 error. The way you do it, with a map, will redirect only known URLs.  Which you prefer is up to you. 

Your other map looks fine.  You can expand it to hundreds of lines.

You can test all your rules and maps using the TestDriver.exe. 

 

 T