Posted By: turrican | Jun 26th @ 11:49 AM
page 1 of 1
Comments: 15 | Views: 1092
It makes your SEO ranking better.
Hm... Why? Because of the words in the URL?
I like it better with the words. It's easier to choose when you start typing the URL and you get the URLs with the titles.
The world of Developers seem to be divided down the middle by this sort of thing.
Some of the most requested questions I get nowadays about ASP.NET 3.5 and IIS7 is, well, URL hacks. Wink
It's also a lot easier if someone links to a forum post, you can see the title of the post when you hover over the hyperlink.
I personally navigate directly to the various forums sometimes, and it's easier just typing http://channel9.msdn.com/Forums/Coffeehouse than http://channel9.msdn.com/ShowForum.aspx?ForumId=14 or something.

It isn't cheating if you are using the real content to create the link. If you use some bogus high rank terms that have nothing to do with the content, then yes... that would be cheating Smiley

I'm personally a big fan of words in the URL, and I wrote the first version of all the URL magic we do on our sites... lots of additional code by everyone else, but my opinion probably steered us in a specific direction as the guy who wrote our url parsing, generating code.

I really think that url shortening services (as necessary as twitter has made them) like tiny url are one of the worst things to ever happen on the web... URLs, from the domain name on down, should have meaning... and they should be 'hackable'. So if you give me a URL like http://blogs.msdn.com/seshadripv/archive/2008/06/30/how-to-invoke-a-python-function-from-c-using-the-dlr-hosting-api.aspx then you should be able to go to http://blogs.msdn.com/seshadripv/archive/2008/06/30/ as well (you can't, by the way). I'd rather not have .aspx at the end either, if I can avoid it... the techology used to show the page has little to do with the content... and the URL should be all about the content.

Yes, URL-rewriting is a great technique. Last week I had to update one of our web applications, and I actually needed URL-rewriting to remain backward compatible. Our previous version had an ASPX-page (document.aspx) to handle document downloads, which was sub-optimal. In the new version, I created an ASHX-handler (document.ashx) that is very lightweight and does the same. But the document.aspx had to keep working because external websites were linking to it. I also added a 3rd URL-format (that is preferred) to access the same document.

  • http://mysite/documents/document.ashx?d=123 : the actual handler
  • http://mysite/documents/document.aspx?d=123 : gets rewritten to document.ashx
  • http://mysite/documents/123.pdf : gets rewritten to document.ashx

The technique I used was this: in Global.asax (I can't remember the method name) I check the requested URL via regular expressions and redirect or rewrite the URL. I also check for regular files (if they exist). In IIS, all file extensions are now handled by the ASP.NET process and everything goes through my Global.asax. This is what I like about ASP.NET: its modular architecture where you can customize pretty much everything. I don't like WebForms, but the architecture with HTTP modules and handlers is awesome.

Cool. Would love to see some small example code how to do that with Global... if possible. : )
Sure, I'll post something tomorrow, when I'm at work.
readonly Regex fRegexUrlRewriter = new Regex(@"^(?<path>.*/documents/)(?<id>[0-9]+)(\.[a-zA-Z0-9]+)?$");
readonly Regex fRegexDocumentAspx = new Regex(@"^.*/document\.aspx.*$");
readonly Regex fRegexAspx = new Regex(@"^.*\.as(p|h)x(\?.*)?$");

protected void Application_BeginRequest(object sender, EventArgs e)
{
    string lPath = Context.Request.Path;
    if (fRegexUrlRewriter.IsMatch(lPath))
        // .../documents/123.ext -> .../documents/document.ashx?d=123
        Context.RewritePath(fRegexUrlRewriter.Replace(lPath, "${path}document.ashx?d=${id}"));
    else if (fRegexDocumentAspx.IsMatch(lPath))
        // .../document.aspx?... -> .../document.ashx?...
        Context.RewritePath(lPath.Replace(".aspx", ".ashx"));
    else if (!fRegexAspx.IsMatch(lPath))
    {
        // not .aspx or .ashx
        string lPhysicalPath = Context.Request.PhysicalPath;
        if (File.Exists(lPhysicalPath))
        {
            string lDirectoryName = Path.GetDirectoryName(lPhysicalPath);
            if (!lDirectoryName.EndsWith(Path.DirectorySeparatorChar + "bin", StringComparison.IgnoreCase))
            {
                Context.Response.TransmitFile(lPhysicalPath);
                CompleteRequest();
            }
            else Context.Response.StatusCode = 403; // forbidden
        }
        else if (!lPath.EndsWith("index.html"))
        {
            if (lPath.EndsWith("/"))
                Context.RewritePath(lPath + "index.html", true);
            else if (Directory.Exists(lPhysicalPath))
                Context.Response.Redirect(lPath + "/");
            else Context.Response.StatusCode = 404; // not found
        }
        else Context.Response.StatusCode = 404; // not found
    }
}
page 1 of 1
Comments: 15 | Views: 1092