SES url in coldfusion

Got this url

http://localhost:8500/users.cfm?userid=John

that loads the user's profile by getting the users details from the db

WHERE userid = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#url.userid#">

How can the same profile be accessed like this:

http://localhost:8500/John

Instead of users having to type "users.cfm?userid=John", they simply type the user id of the person whom they want to view.

On CF9, IIS7

I may need to install http://www.iis.net/download/urlrewrite for the solution, please advice.

Appreciate your help.


Using URLRewrite, have the rewriter set the requested URL (eg /John ) as a request header and forward it to a single .cfm file (ie a front controller). In the .cfm file (eg frontcontroller.cfm) read out the request header (ie GetHttpRequestData().headers ) and process accordingly -> users.cfm?userid=john .


Off-hand, maybe you could use the OnRequest method in Application.cfc. That method allows you to filter requests and give them special processing.

http://www.bennadel.com/blog/805-ColdFusion-Application-cfc-OnRequest-Creates-A-Component-Mixin.htm

In your example, you could take "John", or any string, if it exists at the root, and

<cfinclude template="#application.baseHREF#/users.cfm?userid=#userID#" />

If you define baseHREF in OnApplicationStart.


If you decide to use a tool like ISAPI Rewrite (not free) which allows you to write Rewrite rules similar to those used in Apache, you'd add:

RewriteRule ^(.*)$ /users.cfm?userid=$1 [NC,L,QSA]

You can also add folders or other URLs to exclude from this rule with something like:

RewriteCond %{REQUEST_URI} !^(assets|images|xml|tasks) [NC]
RewriteRule ^_admin/(.*)$ /_admin/index.cfm/$1 [NC,L,QSA]

I would recommend using a rewrite rule over handling it in CFML to reduce the processing handled by the CF server.

链接地址: http://www.djcxy.com/p/31208.html

上一篇: 用于多个域/ URL的本地Coldfusion服务器

下一篇: SES网址在Coldfusion中