Laravel外部URL问题 [英] Laravel external URL issue
问题描述
我想在一些锚标记中设置外部URL,但是当URL不具有http/https协议时会遇到问题.当URL没有这些协议时,URL如下所示:
I want to set external URL in some of my anchor tags but facing problem when URL is without http/https protocol. When URL is without these protocols URL become like following:
<a target="_blank" href="www.usatoday.com/"></a>
当我单击它或将鼠标悬停在它上面时,它会显示并将我重定向到: http://localhost/event/www.usatoday.com
when I click on it or hover over it, it shows and redirect me to: http://localhost/event/www.usatoday.com
我尝试了以下两种使用href的方法,但没有成功:
I've tried following two ways in href but didn't worked:
{{url($eventSponsorsRow->sponsorUrl)}}
{{ $eventSponsorsRow->sponsorUrl }}
代替href中的URL. Laravel 5.3
instead of URL in href. Laravel 5.3
推荐答案
这是HTML和浏览器内容,而不是Laravel/PHP本身.
This is HTML and browser stuff, not Laravel/PHP itself.
您只需要提供url的协议部分即可将其设置为外部.
You just need to provide protocol part of the url to make it external.
您可以跳过http:
,但是它需要在网址前面至少加一个双斜杠,例如:
You can skip the http:
but it needs at least double slash in front of the url like:
<a target="_blank" href="//www.usatoday.com/"></a>
请不要,如果您跳过http(s):
部分,它将使用当前使用的协议.
Please not, that if you skip the http(s):
part it will use currently used protocol.
这篇关于Laravel外部URL问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!