Search Engine Safe URL's (often abbreviated SES) are attractive to Web developers and business owners because they "pretty up" the browser address bar, help search engines crawl through site content, and generally make it easier to share URL's to content deep within a Web site. The advantages to using SES URL's are covered exhaustively throughout the Web if you want more reasons why you should use them. For information on how to set up and configure Apache's mod_rewrite including the creation of SES URL's for a Mach-ii site, read on...

Continue Reading

Aaron West's Gravatar
About this post:

This entry was posted by Aaron West on December 3, 2007 at 8:00 AM. It was filed in the following categories: ColdFusion, Apache, Mach-ii. It has been viewed 133133 times and has 17 comments.

17 Responses to Using Apache's mod_rewrite: SES URL's and More

  1. Thanks for the post.. one thing, for the domain prefix, couldn't you just add

    to the conf?

  2. Great entry Aaron. Somehow I missed this when you first posted it.

  3. Thanks Dave. The information contained in this entry (with fewer examples) will also be available in an upcoming article in the Fusion Authority Quarterly Update Volume 2 Issue 4 (due out in February).

  4. Jason

    Just wondering what you thought about pointing your web server to a .cfm page for your site's 404 handler, and letting ColdFusion parse out the requested template? Has always worked very nicely for me and saves me having to learn url rewriting. But I don't think most folks do it this way. Why wouldn't you do it this way? Great post btw.

  5. @Jason, the two things you mention are actually quite separate. You can utilize URL rewriting on a Web server and still point 404's to a ColdFusion template. The first step is to define a "Missing Template Handler" in your ColdFusion Administrator. Any .cfm file requested - that does not exist - will cause the template you nominate in the Missing Template Handler setting to execute. Of course, missing resources like HTML files, images, and Flash movies will not be handled by this setting. Pointing your Web server to a .cfm page - as you mentioned - is also an option.

    Regardless of the mechanism you use, it is important to have something in place to handle 404's.

  6. Jason

    Hey Aaron - no I'm sorry: I don't mean the missing template handler. I mean actually setting IIS or Apache to serve a dynamic cfm template for any 404 request. That template can then parse out the web server's cgi variables (and they vary so you have to test - but everything I need I've seen on apache, IIS and sun one). A good example is instead of 404'ing every redirect, their 404 handler looks up (and then redirects) to what was requested. I've been taking this further with framework url parameters, etc. But I dont see a lot of people doing it, preferring instead to wade into url rewriting. So I figured I must be missing something - like perhaps that a dynamic 404 is bad practice or slow or something... Thanks - appreciate the exchange -J

  7. Iam a model glue develper and the urls on this framework is slightly different from Machii.
    Can you please help me by providing Apache Mode rewrite rule as well as IIRF rewriter rule for doing the below conversion.

    I need to covert

  8. @Shimju David

    I'll leave you to come up with the proper RegEx to handle Model-Glue URL's. If you follow the examples I've outlined this should be relatively easy to do.

  9. George

    Can you suggest a mod rewrite rule which could handle this.

  10. @George

    To support the kind of URLs you are asking about you'd want to create a regular expression that matched alphanumeric characters followed by a literal dash, followed by another set of alphanumeric characters.

    I'll admit up front, that I've never written a RegEx that did exactly what I wanted on first try. But, the below should get you on your way. There are two parenthetical expressions below which account for the characters before and after a dash in just the first part of your URL:

    In between the two parenthetical expressions is (what I hope) a literal dash character. If you wanted to support URLs that repeated this pattern (your example had three) you'd just copy and paste everything between the last forward slash and second to last forward slash.

    RewriteRule ^/([A-Za-z0-9-]+)-([A-Za-z0-9-]+)/

    Of course, the above RewriteRule isn't complete as I didn't provide the string I want to use as the replacement condition. If I added that such as:

    RewriteRule ^/([A-Za-z0-9-]+)-([A-Za-z0-9-]+)/ /index.cfm?go=$1:$2 [PT,L]

    you'd be rewriting URLs from to

    Since you only provided the source URL and not what you wanted it rewritten to I just made up the above example. Hope this helps.

  11. George

    @Aaron, thanks for the feedback. Sorry for not being more clear. Without any URL rewrite my URL would look like this. index.cfm?L1=25&L2=1&L3=4
    I want it to look like this index.cfm/L1-25/L2-1/L3-4 I am not using Fusebox or MachII. I am using a code based component that is accessed as a singleton
    object onRequestStart to rewrite the URL string. I figured this might be a better way to do it. I did notice that in my error log for Apache I am getting a page not found error.
    Also, will the mod_rewrite work for staright calls without any parameters. How would I add this as well? article.cfm/L1-25/L2-1/L3-4

  12. George

    @Aaron, this is what my virtual host block looks like but I am getting an error restarting this server with this. Any thoughts on what might be wrong.
    #<VirtualHost *:80>
    # ServerAdmin
    # DocumentRoot "C:/projects/gsigminidvworld"
    # DirectoryIndex index.cfm
    # ServerName
    # ServerAlias *
    # RewriteEngine on
    # RewriteLog C:/Program Files/Apache Software Foundation/Apache2.2/logs/
    # RewriteRule ^/([A-Za-z0-9-]+)-([A-Za-z0-9-]+) /index.cfm?L1=$1:$2 [PT,L]
    # ErrorLog "C:/Program Files/Apache Software Foundation/Apache2.2/logs/"
    # CustomLog "C:/Program Files/Apache Software Foundation/Apache2.2/logs/" common

  13. @George - You're getting an error on Apache restart even with your entire VirtualHost block commented out? I'm going to have to do a lot of guessing here, but on Apache 2.2.x you have to explicitly enable virtual hosts. Doing so causes the httpd-vhosts configuration file to be included at startup. If this config file is empty, you might get errors. In the least, I'd leave the examples that come with the file uncommented and see if that gets Apache started.

    You might also try Apache's configtest which is part of the apachectl. On Mac OS X I simply navigate to the directory with apachectl and type: "apachectl configtest" If everything in my configuration files (all of them) check out, Apache will show the text "Syntax Ok." If something is wrong, it will give an error message to help you out.

  14. Hello there! Would you mind if I share your blog with my
    zynga group? There's a lot of people that I think would really enjoy your content.
    Please let me know. Thanks

  15. Yes! Finally something about drive data recovery.

  16. Unquestionably believe that which you said. Your favorite justification appeared to be on the
    net the simplest thing to be aware of. I say too you, I
    certainly get irked while people conside worries that
    they just doo nnot know about. You managed to hit the nail upon the top and defined out
    thee whol thing without having side-effects ,
    people can take a signal. Will probably be back to get more.

    Look att my web blog :: <a href="">marketing</a>;

  17. Hi there to every single one, it's genuinely a fastidious for
    me to visit this web page, it includes helpful Information.