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.