Is it possible to rewrite url using ColdFusion?

前端 未结 3 1703
礼貌的吻别
礼貌的吻别 2021-01-03 08:59

I have got a requirement for generating user friendly urls.I am on IIS.

My dynamic URLs looks like,

www.testsite.com/blog/article.cfm?articleid=4432

3条回答
  •  感动是毒
    2021-01-03 09:49

    First, I hate to recommend reinventing the wheel. Webservers do this and do this well.

    Cold Fusion can do something like this with #cgi.path_info#. You can jump through some hoops as Adam Tuttle explains here: Can I have 'friendly' url's without a URL rewriter in IIS?.


    Option #2: My Favorite: OnMissingTemplate..

    Only available to users of Application.cfc (I'm pretty sure .cfm has no counterpart to onMissingTemplate).

    You can use this function within application.cfc and all affected pages will throw any "missing" urls at this event. You can then place

    
            
            
            
                    
                    
                        
                            
                            
                        
                    
                    
                    
                    
                          
                          
                    
            
    
    

    mt_blog.cfm can have contents like, if your url is say just like /blog/How-to-train-your-flea-circus.cfm

    
    
    
    
    
      select bBody,bTitle,bID
        from Blog
       where urlname = 
    
    
    
    
    ...
    

    Or if you use a url like /blog/173_How-to-train-your-flea-circus.cfm (where 173 is a post ID)

    
    
    
    
    
      select bBody,bTitle,bID
        from Blog
       where bID = 
    

提交回复
热议问题