简体   繁体   English

我正在尝试获取php中的根URL

[英]i am trying to get to the root url in php

I have this link in my db.php. 我的db.php中有此链接。 I want everytime the dropdown menu is clicked it redirect to the corresponding page. 我希望每次单击下拉菜单都将其重定向到相应的页面。

$ROOT_URL = '192.167.1.67/office/';

I want to go to this root url on the navigation every time i click on the link. 每次单击链接时,我想转到导航上的此根URL。

<a href="<?php echo $ROOT_URL; ?>admin/admindashboard.php">Home</a>
<ul class="dropdown-menu">
      <li><a href="addproduct.php">Add Product</a></li>
      <li><a href="product/viewproduct.php">View Product</a></li>
      <li><a href="removedproduct.php">Removed Product</a></li>
    </ul>

instead the page is redirecting as 而是页面重定向为

192.168.1.67/admin/192.168.1.67/admin/product/addproduct.php

How can i solve this problem?? 我怎么解决这个问题??

use protocol before your url like.. 在您的网址之前使用协议。

$ROOT_URL = 'http://192.167.1.67/office/';
OR if having https $ROOT_URL = 'https://192.167.1.67/office/';

If the link points to a local location, you can just use / as root. 如果链接指向本地位置,则可以只使用/作为root。

This, for examples will work: 例如,这将起作用:

<a href="/office/admin/admindashboard.php">Home</a>

If $ROOT_URL is dynamic and you want to include the variable, define it as: 如果$ROOT_URL是动态的,并且您想包含该变量,则将其定义为:

$ROOT_URL = '/office/';

Then you can do: 然后,您可以执行以下操作:

<a href="<?php echo $ROOT_URL; ?>admin/admindashboard.php">Home</a>

Also, the links in the list 另外,列表中的链接

<ul class="dropdown-menu">
  <li><a href="addproduct.php">Add Product</a></li>
  <li><a href="product/viewproduct.php">View Product</a></li>
  <li><a href="removedproduct.php">Removed Product</a></li>
</ul>

point to a relative URL, so when your current URL is /office , the links will point to: /office/addproduct.php . 指向相对URL,因此当您当前的URL为/office ,链接将指向: /office/addproduct.php But if this navigation is also included on a page where the URL is /some/other/url , this link will point to: /some/other/url/addproduct.php . 但是,如果该导航也包含在URL为/some/other/url ,则此链接将指向: /some/other/url/addproduct.php

Unless you are really sure the HTML with the link will only show at a certain path, try to avoid relative URLs. 除非您真的确定带有链接的HTML仅在特定路径下显示,否则请尽量避免使用相对URL。

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

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