Solution 1 :

You have to include the scheme (eg https) in the link — otherwise it’ll be treaded as relative to the current page. In other words, you’ll want the whole

You don’t include any info about how you’re getting this information from the user, but it would be a good practice to check it using something like RegEx for a scheme and append one if it doesn’t exist.

You can also use Javascript to prepend a scheme to URLs where it doesn’t exist, but you’d have to make sure you don’t affect any other links that were meant to be relative. Here’s an explanation of how to do that: Prepending “http://” to a URL that doesn’t already contain “http://”

Problem :

I am trying to make users input links into their posts, onto a post page called using a form input.
In the result, if someone enters, it displays
<a href=""></a>
when clicking on the link, it doesn’t go to, instead it links to
Is there a way to prevent this from happening?

*Edit: I fixed this by entering making the input url, but other solutions would be great!


Comment posted by Dbw

Thank you! I was using a form with a input tag to enter the URLs, but I’ll look into what you mentioned.

Comment posted by jnpdx

If you include some code about how your accept and store that info, you might get a more specific response. Otherwise, feel free to upvote and or accept my answer