格式为“mydomain.com/username”的友好 URL没有模组重写?

发布于 2024-10-05 06:33:23 字数 502 浏览 2 评论 0原文

我想知道除了 Mod Rewrite(使用 fusionbox 框架或直接在 Coldfusion 中)之外是否有更简单的方法来转换 url,如下所示:

from:

http://www.somedomain.com/salmahayek
or 
http://localhost/someApp/salmahayek

to:

http://www.somedomain.com/index.cfm?action=profile.view&name=salmahayek
or
http://localhost/someApp/index.cfm?action=profile.view&name=salmahayek

我的应用程序是现有的 Fusebox 5.5 应用程序。

我只需要补充一点,上面的网址不是静态的,即“salmahayek”可以是任何名称。

任何帮助将不胜感激 谢谢

I would like to know if there's an easier way other than Mod Rewrite (using the fusebox framework or directly in Coldfusion) to convert a url as follows:

from:

http://www.somedomain.com/salmahayek
or 
http://localhost/someApp/salmahayek

to:

http://www.somedomain.com/index.cfm?action=profile.view&name=salmahayek
or
http://localhost/someApp/index.cfm?action=profile.view&name=salmahayek

My app is an existing Fusebox 5.5 application.

I just need to add that the url above is not static, i.e. "salmahayek" could be any name.

Any help would be greatly appreciated
Thanks

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

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

发布评论

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

评论(4

旧人九事 2024-10-12 06:33:23

您可能会使用“经典”方法(不确定 Fusebox 是否会干扰),使用 404 处理程序,类似这样的方法应该可以解决问题:

  1. 在您的服务器上设置 404 处理程序,例如在 .htaccess 中:

    ErrorDocument 404 /404handler.cfm

  2. 设置 404handler.cfm 以环绕框架,例如:< /p>

    <cfset variables.checksok = false>
    <!--- do some checks - example --->
    <cfif cgi.REDIRECT_URL EQ 'salmahayek'>
        <cfset variables.checksok = true>
    </cfif>
    <cfif variables.checksok EQ true>
        <cfheader statuscode="200" statustext="OK">
        <cfset url.action = "profile.view">
        <cfset url.name = cgi.REDIRECT_URL>
        <cfinclude template="index.cfm">
    </cfif>

未经测试,但应该可以工作)

You could potentially use the "classic" way of doing it (not sure if Fusebox will interfere), using a 404 handler, something like this should do the trick:

  1. Set up a 404 hander on your server, e.g. in .htaccess:

    ErrorDocument 404 /404handler.cfm

  2. set up 404handler.cfm to wrap around the framework, e.g.:

    <cfset variables.checksok = false>
    <!--- do some checks - example --->
    <cfif cgi.REDIRECT_URL EQ 'salmahayek'>
        <cfset variables.checksok = true>
    </cfif>
    <cfif variables.checksok EQ true>
        <cfheader statuscode="200" statustext="OK">
        <cfset url.action = "profile.view">
        <cfset url.name = cgi.REDIRECT_URL>
        <cfinclude template="index.cfm">
    </cfif>

(not tested but should work)

神魇的王 2024-10-12 06:33:23

我目前在我的应用程序中做了一些类似的事情,尽管是在 PHP 中:

http://localhost /index.cfm/profile.view/salmahayek/

<cfset urlArgs=listToArray(CGI.PATH_INFO, "/") />
<cfset action=urlArgs[1] />
<cfset name=urlArgs[2] />

这工作得很好,但如果你不想重写,你就必须忍受“index.cfm”。

I've doing some like this in one my apps currently, albeit in PHP:

http://localhost/index.cfm/profile.view/salmahayek/

<cfset urlArgs=listToArray(CGI.PATH_INFO, "/") />
<cfset action=urlArgs[1] />
<cfset name=urlArgs[2] />

This works perfectly, but you have to put up with the "index.cfm" if you don't want to rewrite.

野稚 2024-10-12 06:33:23

我不确定其他人的情况,但我不明白为什么 Mod Rewrite 会很困难,除非你在 IIS 上。重写规则必须类似于:

^(login|register)/([^/\.]+) index.cfm?action=profile.$1&step=$2 [L]
^([^/\.]+)/?$ index.cfm?action=profile.view&name=$1

我添加了一些额外的示例来检查用户是否确实尝试访问注册或登录页面以及他们在那里执行的步骤。

I'm not sure about anyone else, but I don't understand why Mod Rewrite would be difficult, unless you are on IIS. A rewrite rule would simply have to be something like:

^(login|register)/([^/\.]+) index.cfm?action=profile.$1&step=$2 [L]
^([^/\.]+)/?$ index.cfm?action=profile.view&name=$1

I put in some extra examples to check if the user is actually trying to get to the registration or login page and what step they are on there.

韶华倾负 2024-10-12 06:33:23

实际上,我过去已经使用 Application.cfc 的 onMissingTemplate() 方法完成了此操作。您可以对传入的arguments.targetpage执行一些正则表达式,或者在数据库中进行查找。无论哪种方式,您都可以在之后执行 cflocation 到正确的页面。只需记住也传递所有 url 参数即可。

我从未尝试过并且经常想知道的一件事是是否可以在 onRequestStart() 方法中处理?我使用 onMissingTemplate() 遇到的最大问题是你正在执行一个 cflocation 这是一个全新的请求,并且你无法传递表单变量。是的,我知道您可能可以使用 GetPageContext().Forward( strUrl ) 代替,但您仍然会将整个请求生命周期放入原始请求中。通过在 onRequestStart() 中执行此操作,您可以避免这种情况。

有人想测试一下吗?

i've actually done this in past using the Application.cfc's onMissingTemplate() method. you can either do some regexs against the arguments.targetpage that gets passed in or do a lookup in a database. either way you would do a cflocation to the correct page afterward. just remember to pass over any url parameters also.

one thing that i've never tried out and often wondered though is if this could be handled in the onRequestStart() method instead? the biggest problem i have with using onMissingTemplate() is that you're doing a cflocation which is a completely new request and you can't pass through form variables. yes i know you could probably use GetPageContext().Forward( strUrl ) instead, but you're still going threw the entire request lifecycle in for the original request. by doing this in onRequestStart() you would avoid this.

anyone want to test this out?

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