格式为“mydomain.com/username”的友好 URL没有模组重写?
我想知道除了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能会使用“经典”方法(不确定 Fusebox 是否会干扰),使用 404 处理程序,类似这样的方法应该可以解决问题:
在您的服务器上设置 404 处理程序,例如在 .htaccess 中:
ErrorDocument 404 /404handler.cfm
设置 404handler.cfm 以环绕框架,例如:< /p>
未经测试,但应该可以工作)
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:
Set up a 404 hander on your server, e.g. in .htaccess:
ErrorDocument 404 /404handler.cfm
set up 404handler.cfm to wrap around the framework, e.g.:
(not tested but should work)
我目前在我的应用程序中做了一些类似的事情,尽管是在 PHP 中:
http://localhost /index.cfm/profile.view/salmahayek/
这工作得很好,但如果你不想重写,你就必须忍受“index.cfm”。
I've doing some like this in one my apps currently, albeit in PHP:
http://localhost/index.cfm/profile.view/salmahayek/
This works perfectly, but you have to put up with the "index.cfm" if you don't want to rewrite.
我不确定其他人的情况,但我不明白为什么 Mod Rewrite 会很困难,除非你在 IIS 上。重写规则必须类似于:
我添加了一些额外的示例来检查用户是否确实尝试访问注册或登录页面以及他们在那里执行的步骤。
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:
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.
实际上,我过去已经使用 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?