必须使用 MVC 框架来生成干净的 URL 吗?

发布于 2024-09-12 01:34:19 字数 364 浏览 2 评论 0原文

我想要托管的主机不支持服务器端 url 重写,因此无法安装第三方工具来重写 url。

这是 Coldfusion 8,在 Windows 上,IIS。

我知道的另一种选择是使用框架,但我不想采取该路线(时间),因为应用程序按原样运行良好(但 URL 除外)。

纯CF可以生成干净的url吗? 我不需要用于搜索引擎优化的干净网址,而是为了用户可以轻松引用其页面。例如 youtube.com/userpage

有什么建议吗?

如果唯一的选择是使用一个框架,那么哪个框架与传统的cfml''、cfm's & 兼容性最好?氟利昂的?因为从非框架应用程序到框架应用程序的转换中需要对代码进行最少的更改。

感谢您的贡献!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

在巴黎塔顶看东京樱花 2024-09-19 01:34:19

不,您不需要框架或 URL 重写器来获取 http://domain.com/some/url 工作(注意没有index.cfm)。

在 IIS 中,您可以为 404 错误设置自定义错误页面。使自定义错误页面在您的服务器上执行 ColdFusion 页面(例如 /urlhandler.cfm、404.cfm 或 index.cfm)。在该页面中,您可以通过对 cgi.query_string 值使用列表方法,使用 ColdFusion 控制自己的路由。 IIS 将为您提供一个类似于 404 的 url;http://domain.com/the/original/ url,您可以解析它以将访问者路由到您想要的事件。

<!--- 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")>

我们有一个每月接收大约 100 万访问者的网站,该网站仍在使用此方法运行 SES 网址。当我被雇用并发现这个现有代码位于网站的核心并且不会选择重复它时,我感到很震惊,但是,如果您在安装重写器或第三方框架方面受到限制(该客户对网站施加了限制),那么这个解决方案可能适合你。

通过使用上述代码,您可以快速了解如何使用 CF 动态包含所需的 .CFM 文件或根据您的设置执行正确的 CFC 代码。

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.

安穩 2024-09-19 01:34:19

您可以使用 Framework/1 框架或 CFWheels 来实现干净的 URL,但需要在 URL 的开头包含“/index.cfm/”,以便触发 ColdFusion 的应用程序处理程序代码。

编辑:请参阅 Aaron Greenlee 的解决方法,以防止“index.cfm”出现在 URL 中。

即无论您采用哪种方法,如果您无法添加第三方工具来重写 URL(并且不使用 Apache),您的 URL 的形式将是 http://site.com/index.cfm/section/item

例如。
http://site.com/index.cfm/user/login
http://site.cfm/index.cfm/user/signup

FW/1还提供以搜索引擎友好的格式传递 URL 变量的选项

示例:

http://site.com/ index.cfm/user/login/email/[电子邮件受保护]/password/test
是一样的
http://site.com/index.html cfm/user/[电子邮件受保护]&password=test
是一样的
http://site.com/ index.cfm?action=user.login&[电子邮件受保护]&password=test

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/[email protected]/password/test
is the same as
http://site.com/index.cfm/user/[email protected]&password=test
is the same as
http://site.com/index.cfm?action=user.login&[email protected]&password=test

浅浅淡淡 2024-09-19 01:34:19

继续学习框架。大多数人都会为此工作。但是如果你只是不想学习框架。

www.mysite.com/products/
将运行:
www.mysite.com/products/index.cfm

www.mysite.com/products/books
将运行:
www.mysite.com/products/books/index.cfm

Framework/1 和 CFZen 将适用于此,它们是非常简单的 1 文件框架,您可以解决它。

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

框架/1
http://fw1.riaforge.org
http://corfield.org - Framework/1 的作者

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

泼猴你往哪里跑 2024-09-19 01:34:19

您可以不使用 http://yoursite.com/index.cfm/user http://yoursite.com/user.cfm 并捕获 OnMissingTemplate< 中的错误application.cfc 的 /code> 函数。这不需要您设置自定义 404 页面。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文