Skip navigation
Currently Being Moderated

url rewriting

Apr 7, 2011 7:27 PM

If I have a dynamic page that loads content depending on a url parameter (whatever.com/editorial.cfm?id=35), how can I rewrite that to make sense? For every record, I do have a "title" for the editorial, like "The best eateries in town" for instance. Any way to use that in the url instead of the id and still have the id recognized on article.cfm?

 
Replies
  • Currently Being Moderated
    Apr 7, 2011 7:48 PM   in reply to Squiggy2

    Does your server have any form of a "URL Rewriter" tool available?  Is it a Windows or Linux server?

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 7, 2011 11:24 PM   in reply to Squiggy2

    IIS7 has its own rewrite engine, if it's not installed (it's an addon) I'd ask the host if they can install it for you; it's an official Microsoft add-on and doesn't cause any problems. I work for a hosting company and we always install it by default now. Once installed, you can configure your rewrite rules using a web.config file in your web root, so you don't need to contact your hosts to make changes.

     

    Trying to do rewriting in CF is a massive pain, with lots of potential issues with error and 404 handlers and even then it'll only handle pages it's given, such as .cfm, .cfml etc; it won't be able to rewrite any non-CF requests, such as .htm etc.

     

    Rewriting is *definitely* something to be done at the webserver level.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 8, 2011 12:28 AM   in reply to Squiggy2

    So what you're saying is you want an URL like this:

     

    http://whatever.com/editorial/The_best_eateries_in_town/

     

    I agree this is best done via some sort of ISAPI_rewrite module, and not via CF.

     

    How many articles have you got?  One way to do this would be to generate a rewrite map file which maps the article titles to their IDs, eg:

     

    The_best_eateries_in_town 35

    The_best_cinemas_in_town 36

    #etc

     

    (that's be the syntax for mod_rewrite, I dunno how IIS7 handles these things, but know that it does handle them (from my 15sec worth of googling, just now)).

     

    Rewrite maps scale pretty well, so having a mapping for each article - provided you don't have millions of them - would be fine.  You could regenerate this file from your DB periodically, or whenever an article is added / updated / deleted you could run an event handler that updates or recreates the map file.

     

    Then it's just a matter of rewriting your URL from the human-friendly one to the one CF will expect.  It it was mod_rewrite that'd be something like:

     

    RewriteMap title2ID txt:title2ID.map
    RewriteRule ^/editorial/(.*)/ /editorial.cfm?id=${title2ID:$1}

     

    IIS's rewriting engine seems to be all point-and-clicky-based, not .htaccess-based, so dunno how it effects the same thing, but that's pretty much what you want to do.

     

    If you have too many articles to sensibly maintain a map file, then you're gonna need to include the article ID in the URL, thus:

     

    http://whatever.com/editorial/The_best_eateries_in_town/35/

     

    And use a rewrite to grab the "35".  This approach is probably easier, but makes for a slightly less friendly URL (although who really cares?  Who makes any judgements based on the URL... and that'll still be fine for SEO).

     

    --

    Adam

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 8, 2011 12:50 AM   in reply to Adam Cameron.

    I've had need to use the IIS rewrite module recently, and it is very good. As Adam says it does have an interface, but all that does it help you create the web.config file - you can create this locally then just dump it in your web root if you don't have access to the server.

     

    By far the most extensible and future-proof method is to include the Subject Id within the url somewhere so you don't have to map everything out. Look at this Amazon link:

     

      http://www.amazon.co.uk/Practical-Whispering-Threshold-picture-guides/ dp/1872119670/ref=sr_1_1?ie=UTF8&qid=1302248856&sr=8-1

     

    Spot the Id in there? 1872119670. They'll be ignoring everything else in that link (except url parameters) and just using the id to get the data from the database.

     

    I've just tested a rule (I can't remember the exact regex so this one might be a bit shanty) which will allow rewriting of urls on a fairly basic level, but that needs no modifying when you add new first-level pages. The web.config looks like so:

     

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="GenericSubjectId">
                        <match url="^(\w*)/([0-9]+)?/(.*?)/?$" />
                        <action type="Rewrite" url="/{R:1}.cfm?SubjectId={R:2}" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>

     

    What it actually does is matches any url that starts with a word, then a forward slash, then a numeric id, then ignores the rest. This means that from the back of this rule, if I create a link to, say:

     

      /horses/938734/my_biggest_horse_ever/something/pics

     

    Then it actually requests the page "/horses.cfm?SubjectId=938734" from ColdFusion. Likewise, if I go to:

     

      /people/01812/muppets/family

     

    Then I actually get served "/people.cfm?SubjectId=01812".

     

    That's what I'd do if you're not going to be doing too much with subfolders, but even then you can just amend the rule accordingly. Quick-and-dirty one-time-only setup for basic url rewriting!

     

    For. The. Win.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 8, 2011 11:07 AM   in reply to Squiggy2

    Search engines haven't given a sh!t about what's in the URL for about ten years.

     

    It's just pedantic humans with SEO jobs you need to placate.

     

    --

    Adam

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 10, 2011 12:29 PM   in reply to Squiggy2

    Because if SEO experts said "there's nothing mysterious about it, I don't actually know anything more about the vagaries of Google than you do, just use common sense"... well... then... there'd be no SEO experts would there?

     

    If Douglas Adams had been writing HGttG these days, SEO experts would be boarding the Golgafrinchan B-Ark alongside the hairdressers & those people who clean telephone receivers...

     

    --

    Adam

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 10, 2011 12:58 PM   in reply to Adam Cameron.

    +1 @ Adam

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 11, 2011 6:05 AM   in reply to Adam Cameron.

    Adam is right.  URL formats don't make any difference to Search Engines.  However, readable URLs are still preferable.  If I am searching for 'Round widget by brand X in red', I am more likely to click on "www.domain.com/round-widget-brand-x-red" than "www.domain.com/viewItem.cfm?id=12345"

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 11, 2011 7:06 AM   in reply to Adam Cameron.

    Adam, can you cite that information?  I'd love to have some evidence to show anyone that Google (or any other search engine) does not look at the URL.

     

    Jason

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 12, 2011 12:31 AM   in reply to 12Robots

    No, I don't have anything specific, sorry: just random reading, non-scientific analysis of URL indexing & from conversations about SEO stuff from people in the queue waiting to board the B-Ark ;-)

     

    The resounding impression I get is that the most influential consideration - by a long march - is simply to have documents that contain information about the topic one wants to be found in a search on that given topic.  Crazy.  The influence the URL is going to have on this is minimal.

     

    There seemed to be a real consideration as to URL construction years and years ago, and the impression I get is that this has kind of "stuck" in people's minds as being a consideration, despite the issue being one of locating & indexing the document in the first place, not how pretty the URL is.

     

    I think "nice" URLs are a reasonable consideration as far as "actual people" are concerned: http://help.adobe.com/CFML/cfabort/ is going to be far more memorable than http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461 172e0811cbec22c24-7fde.html for example, but it would be churlish of a search engine to consider http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461 172e0811cbec22c24-7fde.html to be "better" than http://help.adobe.com/index.php?lang=en_US&product=ColdFusion&version= 9.0&tag=cfabort.

     

    It would be interesting to see if an SEO "expert" could come up with some evidence to refute this.  But, of course... they don't really know, do they? No.

     

    --

    Adam

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points