Extension less urls in Sitefinity 5.0 after migration from 3

Posted by Community Admin on 03-Aug-2018 13:51

Extension less urls in Sitefinity 5.0 after migration from 3.7

All Replies

Posted by Community Admin on 01-May-2012 00:00

       I have a website in sitefinity 5.0, migrated from 3.7 and I would like all the .aspx pages accessible without the extension(for SEO purpose)
For ex:- www.mysite.com/aboutus.aspx should be accessible as
As per one of the recommendations, I tried the following code to remove extension.

using(var api = App.WorkWith())
    var pages = api.Pages().LocatedIn(PageLocation.Frontend).ThatArePublished()
        .ForEach(page =>
            page.Extension = null;

where will be the ideal place(master page or some other common place) where I can execute this code? Does this code need to be run for evey request or just one time?
Also, after running the above  code, I got the pages working without extension,but now the problem is the pages are not available with extension. How can I make the files available with and without extension?

Posted by Community Admin on 01-May-2012 00:00


The code needs to be run only once after migration (or any time such urls are introduced to your site); once the changes are made they are permanently saved.

You can run this anywhere code can execute, such as a master page or usercontrol code-behind. Personally, I always add a blank test.aspx webform, add my temporary logic to the code-behind, build, load the page, then delete it when I'm done.

As for supporting the old urls with extension, you can do this with something like the IIS Url Rewrite module (I wrote about this briefly when migrating my personal website from Sitefinity 3.7)

The Url Rewrite module allows you to use regex to create 301 redirects, dropping the .aspx extension (as well as a slew of other possibilities like forcing lower-case urls, etc)

I hope this is helpful!

Posted by Community Admin on 03-May-2012 00:00

Thank you for your reply.
I tried with the following code for the url rewriting.
public class UrlRewriting : IHttpModule
        public void Init(System.Web.HttpApplication MyApp)
        MyApp.BeginRequest += new System.EventHandler(Rewriting_BeginRequest);

        public void Rewriting_BeginRequest(object sender, System.EventArgs args)
                HttpApplication inst = sender as HttpApplication;
                string req_path = inst.Context.Request.Path.ToLower();

                if (req_path.IndexOf("/sitefinity/") < 0)
                    if (inst.Context.Request.CurrentExecutionFilePathExtension == ".aspx")
                        if (req_path.IndexOf(".aspx") > 0)
                            req_path = req_path.Replace(".aspx", "");
        public void Dispose()


I was trying to put it under App_Code folder as a .cs file(rewrite.cs), not sure whether this folder is disabled in latest sitefinity 5.0. If yes, is there any better place where I can place this code?
Also , one more disadvantage I found is that, if the user types in www.mysite.com/aboutus.aspx
in the url box of the browser, it is coming as www.mysite.com/aboutus
It is actually doing a response.redirect . If it was server.transfer(new url), the url in the url box will be same(but unfortunately server.transfer doesn't work here). any ideas?

This thread is closed