Redirect to UTF-8 URL with ColdFusion

前端 未结 4 1705
孤城傲影
孤城傲影 2021-01-12 15:11

I\'m working on a system that uses UTF-8 characters in folder names for URLs. There\'s been no problem in navigating to these URLs and everything works as expected - exc

相关标签:
4条回答
  • 2021-01-12 15:57

    Another potential work around for this is to URL Encode the portions of the URL that cflocation will break.

    For example, I have some conditional testing that will 301 redirect if the combination of parameters are known to not work well together. One of those parameters is composed of Greek characters. Our solution is to use URLEncodedFormat() where needed.

    <cfif Translation EQ "LXX" AND (URL.ot EQ "MGNT" OR URL.ot EQ "TR")>
        <cfset URL.word = URLEncodedFormat(URL.word)>
        <cflocation statuscode="301" url="/lang/lexicon/inflections.cfm?strongs=G#myStr.StrongsNum#&t=#URL.ot#&ot=#URL.ot#&word=#URL.word#" addtoken="No" />
    </cfif>
    
    0 讨论(0)
  • 2021-01-12 15:59

    I've tried the above but it couldn't get it to work. I ended up doing the cflocation "manually". Like this:

    <cfprocessingdirective pageencoding = "utf-8"/>
    <cfheader charset="utf-8" name="location" value="geschäft/käfer/">
    <cfheader statuscode="302">
    

    This worked like a charm for me.

    0 讨论(0)
  • 2021-01-12 16:03

    I went to test this and didn't see the same result. But then I played with it a little more and tried using

    <cfprocessingdirective pageencoding = "utf-8"/>
    

    Immediately, I was able to see the exact same issue that you did. It seems natural to include it in any page. This is very speculative, but CFAS may be doing some kind of URL encoding in the cflocation tag when used in conjunction with the pageencoding directive.

    Assuming you have this in your code somewhere, try removing it for the redirect. If that works, then I would report this as a bug to Adobe.

    Just FYI, I did this -- Output with encoding

    <cfprocessingdirective pageencoding = "utf-8"/>
    geschäft/käfer/
    

    And I got

    geschäft/käfer/
    

    But when I did this -- Relocation with encoding

    <cfprocessingdirective pageencoding = "utf-8"/>
    <cflocation url="geschäft/käfer/" addtoken="false" />
    

    It relocated me to

    gesch%E4ft/k%E4fer/
    

    And when I did this --Output without encoding

    geschäft/käfer/
    <cfabort>
    

    I got

    geschäft/käfer/
    

    But when I did this -- Relocation without encoding

    <cflocation url="geschäft/käfer/" addtoken="false" />
    

    Then I was relocated to

    geschäft/käfer/
    
    0 讨论(0)
  • 2021-01-12 16:06

    This is still broken with ACF2018 - the CFHeader work-around does the trick, but... yuck..

    It appears that Lucee (as of 5.3.3.62) also has the same problem.. I've reported it to them as well (LDEV-2456), we'll see what they have to say about it.

    0 讨论(0)
提交回复
热议问题