Removing the .aspx from your DotNetNuke URL
Dec
21
Written by:
Jonathan Sheely
12/21/2011 2:26 PM
DotNetNuke ships with a URL provider that over the years has gone through several updates in how it can handle URLs
Original Method - Default.aspx?TabId=52
Second Version - /Home/TabId/52/Default.aspx
Human Friendly (Current Default) – /Home.aspx
The new human friendly is great but still requires that the user append the .aspx to the end of the page names.
Case Study
Lets say you have a business card or promotion and you want to advertise a specific page on your site that people could actually type in
“www.domain.com/promo”
Typically what you would do is FTP into your DotNetNuke root directory, create a folder called promo and then create a default.htm page to redirect to www.domain.com/promo.aspx
Rewriting the URL
With IIS7 and Url Rewriting you can now add some lines to your web.config file and handle urls without the .ASPX extension. Below is an example of such a rewrite rule and you will place this inside of your node.
<rewrite>
<rules>
<rule name="sanitize aspx">
<match url="(^.*)" />
<conditions logicalGrouping="MatchAll">
<add negate="true" input="{REQUEST_FILENAME}" matchType="IsFile" />
<add negate="true" input="{REQUEST_FILENAME}" matchType="IsDirectory" />
<add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
</conditions>
<action url="{R:1}.aspx" type="Rewrite" />
</rule>
</rules>
</rewrite>
This code works by first making sure that a file or directory with the /promo does not already exist. If it does then the physical file will take precedence over the rewrite rule. Second it will then take the domain url and append the .aspx to the end if it does not exist. So when you type in /promo behind the scenes it is serving up the page /promo.aspx. This is done without redirecting or changing the url.
Now all your URLs in DotNetNuke can be simple and even more pretty.
Update 1/25/2012: Here is an alternative version if you want to do 301 redirects to the page name vs rewriting the url.
<rewrite>
<rules>
<rule name="sanitize aspx" stopProcessing="true">
<match url="(^.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}.aspx" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
6 comment(s) so far...
Re: Removing the .aspx from your DotNetNuke URL
Nice quick config run-down. :)
By Will Strohl on
12/21/2011 2:38 PM
|
Re: Removing the .aspx from your DotNetNuke URL
there must be something more to this, website goes down with 500 error
By Vera on
12/21/2011 3:42 PM
|
Re: Removing the .aspx from your DotNetNuke URL
You need IIS7 and UrlRewrite (which most updated servers have by default) www.iis.net/download/urlrewrite
By Jonathan Sheely on
12/21/2011 3:52 PM
|
Re: Removing the .aspx from your DotNetNuke URL
So I'm guessing the menu items will still include the .aspx so all menu links and any other links generated by DNN will still include the .aspx so you'll have lots of redirects? Seems like a big downside.
By David O'Leary on
12/21/2011 5:11 PM
|
Re: Removing the .aspx from your DotNetNuke URL
David,
Correct, All the DNN menu links will still resolve with a .aspx. However there are no redirects in this method. This is rewriting the URL behind the scene.
The user will enter in /promo and the page will load /promo.aspx The users browser will still show /promo, no redirecting.
By Jonathan Sheely on
12/21/2011 5:16 PM
|
Re: Removing the .aspx from your DotNetNuke URL
*Updated* SyntaxHighlighter was causing problems with case of the xml attributes so I had to remove it. Updated code is now available.
The specific attributes it was effecting were: logicalGrouping & matchType
By Jonathan Sheely on
12/21/2011 5:37 PM
|