Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Oct 27, 2010 @ 16:26
    Jeroen Breuer
    0

    Url rewrite to make website ajax crawlable

    Hello,

    I'm building a flash website which I want to be ajax crawlable. Because of this I want all the url's in Umbraco to be rewritten. Sample:

    Normal url: http://mydomain.com/nl/content

    Should become: http://mydomain.com/#!nl/content

    This way all the pages go to the home page and flash loads the correct page by reading everything after the #!. Can I use the UrlRewriting.Net plugin from Umbraco for this?

    Jeroen

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Oct 27, 2010 @ 16:38
    Stefan Kip
    0

    You could try this (with IIS UrlRewrite):

    Catch wildcard *, this catches all url's and rewrite them to #!{R:0}
    Why use IIS? Because in IIS you can have a Condition that '{REQUEST_FILENAME}' is NOT a file :-)

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Oct 27, 2010 @ 16:53
    Jeroen Breuer
    0

    The whole ajax crawlable stuff is pretty new for me. I think I'm trying to do things way to complicated. I could just go to normal url and make a 301 redirect to the url with #! that I need. I'll post an update when I got it working :).

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Oct 28, 2010 @ 12:19
    Jeroen Breuer
    1

    Ok the 301 redirect works perfect.

    I gave all the url's which need to be redirected a special Crawlable redirect template. All this template does is the following:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Response.RedirectPermanent(string.Format("/#!{0}", Request.Url.AbsolutePath));
        }
    }

    It redirects to the main page. On the main page I get the data of the redirected page by downloading the page with another template. Here is some test code:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string uglyUrl = Request.QueryString["_escaped_fragment_"];
            if (!string.IsNullOrEmpty(uglyUrl))
            {
                string baseUrl = Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
            //Get the url we redirected from with another template
                string ajaxContent = baseUrl + uglyUrl + "/TestPage";
                LitHtmlPage.Text = DownloadWebPage(ajaxContent);
            }
        }
    }
    
    /// <summary>
    /// Returns the content of a given web adress as string.
    /// </summary>
    /// <param name="Url">URL of the webpage</param>
    /// <returns>Website content</returns>
    public string DownloadWebPage(string Url)
    {
        // Open a connection
        HttpWebRequest WebRequestObject = (HttpWebRequest)HttpWebRequest.Create(Url);
    
        // Request response:
        WebResponse Response = WebRequestObject.GetResponse();
    
        // Open data stream:
        Stream WebStream = Response.GetResponseStream();
    
        // Create reader object:
        StreamReader Reader = new StreamReader(WebStream);
    
        // Read the entire stream content:
        string pageContent = Reader.ReadToEnd();
    
        // Cleanup
        Reader.Close();
        WebStream.Close();
        Response.Close();
    
        return pageContent;
    }

    I get the html of the page which just redirected (using a different template) and display it on the main page. This is only done if Request.QueryString["_escaped_fragment_"] is not empty so only when the google crawler is searching the page.

    Now Im stuck at the following point. Per page I need to get different templates depending on the redirected page. So somehow I need to get the templates which are related to the redirected url. Is there a way to get the umbraco node id based on the url? Is this a nice way of making a flash website crawlable? If anyone has a better idea I'm open for suggestions :).

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Nov 04, 2010 @ 09:22
    Jeroen Breuer
    0

    Just want to give this topic a little kick. Are there any more developers who use this ajax crawlable technique and how do you use it with Umbraco?

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 17, 2011 @ 16:58
    Jeroen Breuer
    0

    And another kick. Is there anybody who uses the ajax crawlable technique with Umbraco? If so please share your experience.

    Jeroen

  • Trevor Loader 199 posts 256 karma points
    Sep 04, 2012 @ 11:34
    Trevor Loader
    0

    Can't you just throw the following line into /config/UrlRewriting.config?

    <add name="crawlable" virtualUrl="^~/(.+)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/!#$+" ignoreCase="true" />

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Sep 04, 2012 @ 11:44
    Jeroen Breuer
    0

    Haven't tried that, but I do know that redir with a # in the url could give problems. Eventually ended up using javascript:

            <script type="text/javascript">
    
                //Do a redirect to the home page with the original url after the #!.
                //The page will be loaded on the home page with javascript.
                //Querystrings are currently not supported, but we don't use them.
                //We tried this with a Response.Redirect and Response.PermanentRedirect but somehow that didn't work.
                window.location.href = '/#!<%=Request.Url.AbsolutePath%>';
            </script>

    Jeroen

  • Trevor Loader 199 posts 256 karma points
    Sep 04, 2012 @ 11:48
    Trevor Loader
    0

    Sweet that you've got a solution! T

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Sep 04, 2012 @ 11:48
    Jeroen Breuer
    0

    And the problem with that rewrite rule is that everything get's redirected, but we still need to be able to go to pages with alternate templates and I'm also not sure if /umbraco/ would work.

    Jeroen

  • Trevor Loader 199 posts 256 karma points
    Sep 04, 2012 @ 12:14
    Trevor Loader
    0

    I think /umbraco still works as they must ensure that we can't put something stupid into the rewrite rules to break umbraco??

    The notation for excluding is a directoryis something like ((?!blah).+) and if you want to exclude more than one directory at the same level, then I think ((?![xxx|yyy].+) should work.  I'm pretty new to urlrewriting but I've managed to get a few tricky rewrite rules working with uWebshop etc.

    I've not tried to exclude matching on a querystring (alttemplate)...I might do a test in the morning for my own benefit.

    Cheers, T

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Oct 01, 2012 @ 15:23
    Jeroen Breuer
    0

    If someone would like to know I used uQuery.GetNodeByUrl(string) to get the id based on the url which I mentioned here at the end of the post.

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft