简体   繁体   English

使内部链接成为外部链接

[英]make internal link to be external

So, 所以,

  1. web site have a user profile 网站上有一个用户个人资料
  2. user can edit own profile 用户可以编辑自己的个人资料
  3. profile data have "site" data field 个人资料数据具有“站点”数据字段
  4. user can enter some site url and after that this url will shown in profile like a link 用户可以输入一些网站网址,然后该网址将在个人资料中显示为链接

if user enter site with protocol ( https://facebook.com ) there is no problem and it goes to https://facebook.com 如果用户使用协议( https://facebook.com )输入网站,则没有问题,并且转到https://facebook.com

but if user enter something like this facebook.com it will be internal link and goes to https://my.site.com/facebook.com 但是,如果用户输入类似此facebook.com的内容,它将是内部链接,并转到https://my.site.com/facebook.com。

how can i avoid this situation? 我如何避免这种情况?

Check if there is :// in the entered data. 检查输入的数据中是否有:// If not then add http:// 如果没有,请添加http://

除非您需要进行一些高级检查,否则只需在他们添加网址/网站时对其进行检查-如果“ site”值不是以http://或https://开头,则只需在添加前将其添加它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM