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?
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 :-)
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 :).
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 :).
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>
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.
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.
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
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 :-)
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
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:
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
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
And another kick. Is there anybody who uses the ajax crawlable technique with Umbraco? If so please share your experience.
Jeroen
Can't you just throw the following line into /config/UrlRewriting.config?
Haven't tried that, but I do know that redir with a # in the url could give problems. Eventually ended up using javascript:
Jeroen
Sweet that you've got a solution! T
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
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
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
is working on a reply...