Solved

Convert links for to querystring

Posted on 2010-11-15
3
320 Views
Last Modified: 2012-08-13
I am trying to write a mobile version of a website, but am having problems passign the href tags and staying within my mobile version.

To make this successful, I need to rewrite all the href tags to pass through a querystring, so href=/mylink.asp now goes to href=/m/?r=mylink.asp.  Any URL has to be adjusted.  I tried this in the simple way by just finding any href tag, and adding the query id to it, but this does not account for root relative links vs page relative links.  See code below.  

I am sure I am not the first to try and do this, so any help would be very much appreciated.
<cfoutput>

    <!--- PASSES CURRENT PAGE URL, SET TO ABOUT FOR THIS SAMPLE--->

    <cfset url.r = 'aboutus.cfm'>

    <!---GET CONTENTS OF URL--->

    <cfset tempURL = "http://"&#CGI.SERVER_NAME#&#url.r#>

    <cfhttp url=#tempURL#></cfhttp>

    <cfset tempInfo = #cfhttp.filecontent#>

    

    <cfscript>

    //FIND STRING TO STRIP

    startPos = find('<h1 class', tempInfo);

    endPos = find('contentPrimary -->', tempInfo);

    cutLength = endPos - startPos;

    tempInfo = Mid(tempInfo, startPos, cutLength);

    

    //REPLACE any HREF that does not start with http

    

    //THIS IS WHERE I AM NOT SURE HOW TO PROCEED

    tempInfo = replace(tempInfo, 'href="/', 'href="/m/?r=/', 'all');		//REPLACES ALL HREF TAGS INTO QUERY STRING

	tempInfo = replace(tempInfo, 'href="/m/?r=http', 'href="http', 'all');	//REMOVES WHAT I JUST DID IF URL BEGINS WITH HTTP

    

    //STILL TO SOLVE

    //IF URL IS DOCUMENT RELATIVE

    //IF URL ALREADY CONTAINS A QUERYSTRING (CONVERT EXISTING ? to &)

    

    writeOutput(tempInfo);

	

    </cfscript>

</cfoutput>

Open in new window

0
Comment
Question by:mopar003
  • 2
3 Comments
 

Expert Comment

by:macrem
ID: 34144116
Have you tired ReplaceNoCase() ?
You'll find it is safer when you don't know the incoming case.
CGI.SERVER_NAME generally returns uppercase.

0
 
LVL 1

Accepted Solution

by:
mopar003 earned 0 total points
ID: 34146788
Found my own solution.  Searching through all href tags on the page, then checking to see if they were root or document relative.
0
 
LVL 1

Author Closing Comment

by:mopar003
ID: 34182414
Alternate solution found
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Coldfusion HTTPS 2 63
Renaming file after uploading in Coldfusion 4 220
CFLogin explained 10 85
need help with one more  outer join sql query in coldfusion 4 44
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now