Must one use an MVC FrameW to produce clean URL

2019-06-02 08:56发布

The host that I want to host with does not support server side url rewriting, thus no third party tools can be installed to rewrite the url's.

This is Coldfusion 8, on windows, IIS.

The other alternative that I know of is to use a framework, but I do not feel like taking that route (time), for the application works well as it is (but the URL).

Can clean urls be generated by purely CF? I do not need the clean url's for seo, rather it will be for the user's easy reference to their page. E.g. youtube.com/userpage

Any sugessions?

If the only choice is to use a framework, then which one is most compatible with traditional cfml'', cfm's & CFC's? In that there needs to be minimum changes to the code in the conversion from the none frameworked app to become frameworked.

Thanks for you contributions!

4条回答
Emotional °昔
2楼-- · 2019-06-02 09:05

No. you do not need a framework or URL rewriter to get http://domain.com/some/url to work (notice no index.cfm).

In IIS you can set up custom error pages for 404 errors. Make the custom error page execute a ColdFusion page on your server (/urlhandler.cfm, 404.cfm or index.cfm for example). Within that page, you can control your own routes with ColdFusion by using list methods on the cgi.query_string value. IIS will provide you a url that looks something like 404;http://domain.com/the/original/url which you can parse to route the visitor to your desired event.

<!--- Get URL String --->
<cfset CurrentURL = ListGetAt(cgi.query_string, 2, ";")>
<cfset CurrentURL = Replace(CurrentURL, ":80", "")>
<cfset CurrentURL = Replace(CurrentURL, ":443", "")>
<cfset CurrentURL = Replace(CurrentURL, "403;", "")>
<cfset CurrentURL = Replace(CurrentURL, "'", "", "ALL")>

We have a site that receives approx a million visitors a month that is still running SES urls with this method. I was shocked when I was hired and found this existing code at the heart of the site and would not elect to repeat it, but, if you have limitations on installing a rewriter or third party framework (this client placed restrictions on the site) this solution may work for you.

By playing with the above code, you can quickly see how you may use CF to dynamically include the .CFM file you want or execute the right CFC code depending on your set up.

查看更多
做自己的国王
3楼-- · 2019-06-02 09:14

You can use the Framework/1 framework or CFWheels to achieve clean URL's but it will need to include the "/index.cfm/" at the beginning of the URL in order to trigger ColdFusion's application handler code.

EDIT: Please see Aaron Greenlee's work around to prevent the "index.cfm" from appearing in the URL.

i.e. Whichever approach you take, if you cannot add a 3rd party tool to rewrite URLs (and not using Apache), your URL's will be in the form of http://site.com/index.cfm/section/item

eg. http://site.com/index.cfm/user/login http://site.cfm/index.cfm/user/signup

FW/1 offers the option of passing in URL variables in a search engine friendly format as well.

Examples:

http://site.com/index.cfm/user/login/email/me@you.com/password/test is the same as http://site.com/index.cfm/user/login?email=me@you.com&password=test is the same as http://site.com/index.cfm?action=user.login&email=me@you.com&password=test

查看更多
霸刀☆藐视天下
4楼-- · 2019-06-02 09:17

Go ahead and learn a framework. Most will work for this. However if you just do not want to learn a framework.

www.mysite.com/products/ will run: www.mysite.com/products/index.cfm

www.mysite.com/products/books will run: www.mysite.com/products/books/index.cfm

Framework/1 and CFZen will work for this a they are very simple 1 file frameworks that you can just work around.

CFZen http://cfzen.riaforge.org http://cftipsplus.com/blog/?tag=cfzen

Framework/1 http://fw1.riaforge.org http://corfield.org - the author of Framework/1

查看更多
ゆ 、 Hurt°
5楼-- · 2019-06-02 09:29

Instead of using http://yoursite.com/index.cfm/user, you can do http://yoursite.com/user.cfm and catch the error in the OnMissingTemplate function of application.cfc. This will not require you to set a custom 404 page.

查看更多
登录 后发表回答