Archive
Monthly
Go
|
|
DNN Blog
Feb
11
Posted by:
Joe Brinkman
2/11/2006 8:00 AM
A client recently asked me if it was possible to create a friendly url for a specific page on their site. The regular URL looked like this: http://[Host Domain]/en/Help/tabid/89/Default.aspx. This is ok, but not real friendly so I added a rule to SiteUrls.config
<REWRITERRULE> <LOOKFOR>[^?]*/Help/(.*)</LOOKFOR> <SENDTO>~/Default.aspx?TabId=89</SENDTO> </REWRITERRULE>
This results in a much friendlier URL: http://[Host Domain]/en/Help/Default.aspx. The client thought that was good, but they wanted it even friendlier. They didn't want to have the Default.aspx in the URL so that it would just be: http://[Host Domain]/en/Help/. I started scratching my head. This was a big problem because without the .aspx file, then IIS would handle the request as a simple directory request and would never call ASP.Net ISAPI, which would mean our UrlRewriter would never be called.
But then it struck me. What if I just created a directory in IIS so that it had an actual directory to work with? Well this didn't exactly work because I was still left with IIS trying to handle the request itself. So I added an empty file called default.aspx to the new directory. Since default.aspx is one of the default filenames, IIS found the file and called ASP.Net, which handed the call off to DNN and the UrlRewriter. This works, but I am not really happy since this requires a physical directory corresponding to each friendly URL.
So I created a "VirtualFriendlyUrl" directory in my DNN directory with the dummy default.aspx. After I had a single physical directory, then I could create as many IIS Virtual Directories which pointed to my placeholder directory. Now I have a single physical directory, and a bunch of virtual directories, which should make maintenance much easier going forward. Like many things in DNN, thinking outside the box can sometimes result in some simple and elegant solutions to otherwise difficult problems.
10 comment(s) so far...
Re: Friendly Urls Hack
One thing I forgot to mention, make sure you give the virtual directory Scripts Only execute permissions.
By jbrinkman on
2/11/2006 6:28 PM
|
Re: Friendly Urls Hack
I was looking for a fix to a missing moduleID problem I'm having and ran across some stuff Scott McCulloch was writing into a new version of UrlRewriter It sounds like it will be able to do what you want it to also.
By Adeian on
2/11/2006 8:35 PM
|
Re: Friendly Urls Hack
i've done this before with multiple physical directories and the default.aspx per directory. each default aspx file containing a redirect. -- ugly.
for this hack to work you need access to the hosted IIS, correct? if so, this won't work for many of us. is there another way?
By afromobile on
2/12/2006 4:10 PM
|
Re: Friendly Urls Hack
You don't need access to IIS. You just need to be able to create a single physical directory and multiple virtual directories. Most of the Shared Host control panels allow the user to add virtual directories, depending on how your hosting provider has the control panel configured.
By jbrinkman on
2/12/2006 4:55 PM
|
Re: Friendly Urls Hack
The other way to handle this problem is to create a 404 error handler in IIS that points to an aspx file.
Then, during application_beginrequest in global.asax.(vb/cs) you check the query string to see if it starts with "404;" Everything after "404;" is where the request was originally headerd. So, you can pull out that information redirect, using Context.RewritePath(), accordingly.
By DaveMBush on
2/15/2006 8:41 AM
|
Re: Friendly Urls Hack
Dave, That is an interesting hack. I am not sure how this would work with the current URL Rewriter though. Have you successfully gotten this technique to work with the existing URL Rewriter?
By jbrinkman on
2/15/2006 9:00 AM
|
Re: Friendly Urls Hack
Joe: I have a running website on DotNetNuke 3.2.2 The problem is when FUrls are enabled, every link I click on, gives me page not found error. I have the SiteUrls.Config in the root, are there any IIS permissions I should give to make FUrls work?
Thanks,
By bhaidar on
3/5/2006 5:25 AM
|
Re: Friendly Urls Hack
Joe: I have a running website on DotNetNuke 3.2.2 The problem is when FUrls are enabled, every link I click on, gives me page not found error. I have the SiteUrls.Config in the root, are there any IIS permissions I should give to make FUrls work?
Thanks,
By bhaidar on
3/5/2006 5:26 AM
|
Re: Friendly Urls Hack
I'll throw in one more way of doing this. Create a DNN child portal called www.yourdomain.com/help. Then set the redirect of the home page of this child portal to the URL of the page you want it to go to on the parent portal. This is nice becuase it is all handled in DNN and survives any DNN core updates.
By wshackne on
3/30/2006 5:24 PM
|
Re: Friendly Urls Hack
I am stuck as in how do we use Friendly URLS for HTML content.We have lot of help files generated in HTML but we dont want to share the link for the Help files.Is there any way we can do it using friendly url.
By satish125 on
5/23/2006 11:00 AM
|
|