Search code examples
regexreplacecoldfusioncfml

Adding mobile/ to application domain in CFML


I'm having trouble with embedded page links on a mobile site I've inherited. The CMS obviously wants to use the desktop site for all its page links, which is taking people way from the mobile version. I'm a complete n00b in CFML and I'm sure it's pretty simple, but I need to get every link on the page that currently shows as:

http://www.example.com/

to be replaced with:

http://www.example.com/mobile/

I looked at REGEX and my brain melted. Please can someone show me how to do a replace for this? Thank you :)

PS I don't have application.cfm in the /mobile folder where I would expect to specify a new domain like this. I tried it but on clearing the cache it hangs the site so I've had to remove it.


Solution

  • To avoid further overcomplication, I mixed it up with jQuery...

    <script type="text/javascript">
    $(document).ready(function() {
      $("a[href^='/']").each(function(){ 
        var cur_href = $(this).attr("href");
        if( cur_href.indexOf( "http" ) !== -1 ) {
            $(this).attr("href", cur_href);
        } else {
            $(this).attr("href", '/mobile'+cur_href);
        }  
      });
    });
    </script>
    

    The links turned out to be relative, else it would have been one line of code using the application domain variable.