首页 > 解决方案 > 我应该在我的网站中使用哪个路径?相关路径绝对路径?

问题描述

我正在为我的客户建立网站。我想知道我的网站应该使用哪个路径?哪条路径更安全?如果我完全错了,或者您有其他网站安全问题的原因,也请纠正我!提前致谢。

例如...

<script src="https://example.com/admin/js/myjavascript.js"></script>
or
<script src="/js/myjavascript.js"></script>

<img src="https://swadtiffin.ca/wp-content/uploads/myimg.jpg" alt="Loading...!">
or
<img src="/wp-content/uploads/myimg.jpg" alt="Loading...!">

$http({
  method: 'POST',
  url: '/wp-content/themes/astra-child/php/get_all_food_combos.php',
  data: $.param({ 'data': "test" }),
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
  }).then(function (resp) {
  console.log(resp.data); //all items
  });
  }, function (error) {
     console.log(error);
  });

or

$http({
  method: 'POST',
  url: 'https://example.com/wp-content/themes/astra-child/php/get_combos.php',
  data: $.param({ 'data': "test" }),
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
  }).then(function (resp) {
  console.log(resp.data); //all items
  });
  }, function (error) {
     console.log(error);
  });

标签: javascripthtmlwebpath

解决方案


你的两种方式都可以。安全也不例外。但在不同的场景中使用。

  • 如果您为服务添加 URL 前缀。 (https://example.com/wp-content/...php)这意味着您只能从此 URL 获取数据。如果您在另一个网站上运行服务,则必须以这种方式进行。

  • 如果您不添加前缀,它将自动在您的本地路径中使用服务。


推荐阅读