SiteUrls, config, DNN, DotNetNuke, OWS, Open Web Studio, SEO, Search Engine Optimization, Friendly URLs

R2i DotNetNuke Blog

Reading and Writing to the SiteUrls.config file via OWSJaina Baumgartner | Nov 21 2011 | 5 Comments

The SiteUrls.config file in DotNetNuke (DNN) is used for automatic redirection.  It is especially useful for delivering complete URLs without querystring parameters for SEO purposes.  An obvious example of the use of the SiteUrls.config file is the replacement of the TabId querystring parameter with the actual tab name in the URL (“/default.aspx?TabID=5” to “/child1.aspx”).  Search engines do not parse querystring parameters, and hence, the pages in DNN would not be parsed separately without unique URLS utilizing the tab names.  The SiteUrls.config file has extremely simple XML syntax that we can copy to read and write to this file.  The default DNN SiteUrls.config file contains some redirection rules, including the TabId example described above.  In Open Web Studio (OWS), however, dynamic pages are generally created that require querystring parameters.  An example of this is content in the content module, where the pages are generated based on the querystring parameter topic.  Here the SiteUrls.config file can be used to present each piece of content as a separate page to search engines.

XML Syntax

The XML syntax of the default SiteUrls.config file delivered with the DNN instance is displayed below:
 
<?xml version="1.0" encoding="utf-8" ?>
<RewriterConfig>
    <Rules>
        <RewriterRule>
            <LookFor>.*DesktopDefault.aspx(.*)</LookFor>
            <SendTo>~/Default.aspx$1</SendTo>
        </RewriterRule>
        <RewriterRule>
            <LookFor>.*EditModule.aspx(.*)</LookFor>
            <SendTo>~/Default.aspx$1</SendTo>
        </RewriterRule>
        <RewriterRule>
            <LookFor>.*/TabId/(\d+)(.*)/Logoff.aspx</LookFor>
            <SendTo>~/Admin/Security/Logoff.aspx?tabid=$1</SendTo>
        </RewriterRule>
        <RewriterRule>
            <LookFor>.*/TabId/(\d+)(.*)/rss.aspx</LookFor>
            <SendTo>~/rss.aspx?TabId=$1</SendTo>
        </RewriterRule>
        <RewriterRule>
            <LookFor>.*Telerik.RadUploadProgressHandler.ashx(.*)</LookFor>
            <SendTo>~/Telerik.RadUploadProgressHandler.ashx$1</SendTo>
        </RewriterRule>
        <RewriterRule>
            <LookFor>[^?]*/TabId/(\d+)(.*)</LookFor>
            <SendTo>~/Default.aspx?TabId=$1</SendTo>
        </RewriterRule>
        <RewriterRule>
 <LookFor>.*BannerClickThrough.aspx(.*)</LookFor>         <SendTo>~/DesktopModules/Admin/Banners/BannerClickThrough.aspx$1</SendTo>
        </RewriterRule>
    </Rules>
</RewriterConfig>
 
Each Rule is defined under the “RewriterRule” element.  The URL within the “LookFor” element is redirected to the URL within the “SendTo” element.
 
Reading the SiteUrls.config
The SiteUrls.config file can be read with a query action in OWS.  The query is written with the following XML syntax, rather than the usual SQL query:
 
<XML>
                <PATH>~/SiteURLs.config</PATH>
                <NAMESPACES>
                       <NAMESPACE>
                            <URI>http://www.w3.org/2001/XMLSchema</URI>
                            <PREFIX>xsd</PREFIX>
                        </NAMESPACE>
                                <NAMESPACE>
                           <URI>http://www.w3.org/2001/XMLSchema-Instance</URI>
                           <PREFIX>xsi</PREFIX>
                        </NAMESPACE>
                </NAMESPACES>
                <ROWS>/RewriterConfig/Rules/RewriterRule</ROWS>
                <COLUMNS>
                        <COLUMN>
                                <NAME>LookFor</NAME>
                                <XPATH>LookFor</XPATH>
                        </COLUMN>
                        <COLUMN>
                                <NAME>SendTo</NAME>
                                <XPATH>SendTo</XPATH>
                        </COLUMN>
                 </COLUMNS>
</XML>
 
The Path tag delivers the SiteURLs.config file in relation to the root of your website.  The Path delivered in the example above should almost never need to be changed.  Namespaces are required in OWS XML queries.  Hence, the example above defines the two default XML namespaces for XMLSchema (xsd) and XML Schema Instance (xsi). 
 
The Row element is a path from the root element in the config file, to the repeated element that will return rows of data in our result set.  In the SiteUrls.config file, the root element is “RewriterConfig” and the repeated element is “RewriterRule”.  Thus, the path defined for rows is “RewriterConfig”, whose child is “Rules”, whose child is “RewriterRule”. 
 
The columns in our result set will be the value of the elements “LookFor” and “SendTo”.  The “Name” element defines the column name returned in our result set, whereas the “XPath” element defines the path to the column from the row in the config’s XML.  In the SiteUrls.config file, “LookFor” and “SendTo” are immediate children of the “RewriterRule” row defined.
 
The result set returned from our defined XML and SiteUrls.config file displayed above is presented below:
 
LookFor
SendTo
.*DesktopDefault.aspx(.*)
~/Default.aspx$1
.*EditModule.aspx(.*)
~/Default.aspx$1
.*/TabId/(\d+)(.*)/Logoff.aspx
~/Admin/Security/Logoff.aspx?tabid=$1
.*/TabId/(\d+)(.*)/rss.aspx
~/rss.aspx?TabId=$1
.*Telerik.RadUploadProgressHandler.ashx(.*)
~/Telerik.RadUploadProgressHandler.ashx$1
[^?]*/TabId/(\d+)(.*)
~/Default.aspx?TabId=$1
.*BannerClickThrough.aspx(.*)
~/DesktopModules/Admin/Banners/BannerClickThrough.aspx$1
  
Writing to the SiteUrls.config File
After reading from the SiteUrls.config file, the results of the query can be combined with a concatenated assignment action in OWS, with the following value stored in an action variable:
   
<RewriterRule>
      <LookFor>[|lookfor,SITEURLS]</LookFor>
      <SendTo>[|sendto,SITEURLS]</SendTo>
 </RewriterRule>
 
Additional rules can then be appended to the same action variable in a similar format.  Using a File action, such as the one below, the action variable can be stored as the new SiteUrls.config file.  While testing out this OWS config, remember to make a copy of your existing SiteUrls.config file.
 
  
Conclusion
The SiteUrls.config file can easily be manipulated in OWS to deliver an SEO friendly listing of URLs when querystring parameters are used to generate dynamic pages.  An example OWS config is attached that will create a SiteUrls.new.config file in your DNN instance.  To copy over the existing SiteUrls.config file, simply change the “Destination” value in the File action of the OWS config to “~/SiteUrls.config.  To add new rules to the file, change NEWURLS query in line 12 of the OWS config.  This OWS config also generates the result set of the new SiteUrls.config file onto the page.  To remove this, simply delete the last two lines of the OWS config.

Comments

# ainol novo7 | Sunday, December 11, 2011 11:15 PM
Your article was a good read, and I like the way you write. By the way, let me recommend you an ainol novo7 as an awesome X-mas gift. Hope you'll like it.
# Portable Multimedia Player | Wednesday, February 15, 2012 1:06 AM
Thank you for the excellent article 。 My husband and I were very impressed with all the issues that she addressed. ME-A84
They will be a big help to us, not to

mention to the many families that are now and in the years ahead that will be caring for their parents and/or aging family members! Great job, Kathryn! It's a "keeper"!
Most Sincerely, Mr & Mrs Kloth
# Teclast A15 | Friday, February 17, 2012 12:16 AM
Some of the points you have raised will assist me greatly. I like the way you have structured your site, ACHO C905
it is super and very easy to follow. I have bookmarked you and will be back regularly.
# Ben | Saturday, February 18, 2012 2:31 AM
Thanks for making this so easy to follow. I like being able to see the XML syntax laid out. On my brother's Yamaha YPG-235 we tend to find things easy to navigate but here it's useful to have things presented fully
# boardaaa | Wednesday, February 22, 2012 10:53 PM
Your blog is so beautiful and natural all are like your blog everyone appreciate your blog. Whenever We will see your blog every time we get something new about your blog This is the very informative content. I am very appreciate to your site who provide us this Dapeng A9000


informative resource thank for sharing us this information.

Name (required)

Email (required)

Website

Enter the code shown above:

 
Topic not found! Create this topic by clicking the edit link provided above.
 
 

Most Discussed

 

Subscribe to our blog

 

New York, NY • Baltimore, MD • Vienna, VA • St. Louis, MO • Seatle, WA • 410.327.0007 • info@R2Integrated.com

Bookmark & Share Bookmark and Share