function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KruviKruvi 

apex:outputLink redirecting to the wrong URL

Hi

 

I have an apex:outputLink field inside a table cell.

I set the value to: www.mysite.com but when I press the link I get directed to https://c.na12.visual.force.com/apex/www.mysite.com

 

I can't understand why this is happening and how to fix it.

 

Any advise is appreciated.

 

Thanks

 

Oded

Best Answer chosen by Admin (Salesforce Developers) 
Jake GmerekJake Gmerek

I did some quick testing and you do need external links in the form http://www.whatever.com or it treats it as a local page reference. So you have three choices:

 

1.  Make sure that pe.URL__c is in the form http://www.mysite.com.

 

2. Make sure that pe.URL__c is always in the form www.mysite.com and change your tag to:

      <apex:outputLink value="http://{!pe.URL__c}" styleClass="outputLinkStyle" id="productionLink">

 

3.  Use your controller to chek the first 7 characters of pe.URL__c and then return an appropiate string based on the results.

All Answers

Jake GmerekJake Gmerek

Can you post the code?

 

I think though from what you are saying that if you set the value to http://www.mysite.com it might work.

KruviKruvi

This is my code:

 

<apex:column >                  

    <apex:outputLink value="{!pe.URL__c}" styleClass="outputLinkStyle" id="productionLink">{!pe.URL__c}</apex:outputLink>

</apex:column>

 

Where pe.URL__c gets the url field on my object.

 

Thanks

 

Oded

srikeerthisrikeerthi

Hi

 

Please specify the URL as value="https://www.mysite.com".I think this will help you.

 

 

Thanks

Jake GmerekJake Gmerek

I did some quick testing and you do need external links in the form http://www.whatever.com or it treats it as a local page reference. So you have three choices:

 

1.  Make sure that pe.URL__c is in the form http://www.mysite.com.

 

2. Make sure that pe.URL__c is always in the form www.mysite.com and change your tag to:

      <apex:outputLink value="http://{!pe.URL__c}" styleClass="outputLinkStyle" id="productionLink">

 

3.  Use your controller to chek the first 7 characters of pe.URL__c and then return an appropiate string based on the results.

This was selected as the best answer
KruviKruvi

Even when I hard-code the url into the value I get the same behavior

 

Jake GmerekJake Gmerek

Here I copied and pasted this from a working page I have, you can try it and see if it works for you.

 

<apex:outputLink value="http://www.google.com" target="_blank">Google</apex:outputLink>

 

If it does not could you post the whole page code so I can take a look as it would have to be something else in the page causing the behavior.

KruviKruvi

I want to use the 2nd option you suggested above but when I add http:// to my value like this:

 

<apex:outputLink value="http://{!pe.URL__c}" styleClass="outputLinkStyle" id="productionLink">{!pe.URL__c}</apex:outputLink>

 

I get an error.

Am I missing something?

srikeerthisrikeerthi

 

Remove this {!pe.URL__c} there and place any text in that place.

 

Thanks

KruviKruvi

Got it to work.

 

Thank you all

Jake GmerekJake Gmerek

I am glad you got it!!

mackendw@gmail.commackendw@gmail.com

What was done to make it work?  I'm having the same issue...

 

Appreciate posting what you did to fix this.

 

In my controller, I extract the ContentUrl from the ContentVersion object.  This string is stripped of the https:// portion and set in a String property in the class named: 

 

contentUrl

 

This is then referenced in my VisualForce page using:

 

                 <apex:outputLink target="_blank" title="{!$Label.TandC_Label}" value="https://{! contentUrl}">Read Terms</apex:outputLink>

 

Does this look correct?

 

thx.

 

 

KruviKruvi

This is what I finally used:

 

<apex:outputLink value="http://{!pe.URL__c}" styleClass="outputLinkStyle" id="productionLink">{!pe.URL__c}</apex:outputLink>

 I included a tool-tip for my users to not include the http:// prefix when they enter the URL in the field.

 

 

GarrettzGarrettz
Another possibility, in addition to what Jake Gmerek posted is to put the logic in the visualforce iteslf:
 
<apex:outputLink value="{!IF(BEGINS(LOWER(pe.URL__c), 'http'), pe.URL__c, 'https://'+pe.URL__c)}{!pe.URL__c}</apex:outputLink>

I suggest checking if it begins with 'http' as opposed to 'http://' in case there are secure connections.