[英]About HTML and attribute href
晚上好,我對href
屬性有href
因為我不知道如何訪問文件夾,下面舉一個例子:
我留在root / store / products / details.php
我想去root / index.php
我的答案是:如何到達root / index.php? 我一直在嘗試../../index,但是沒有用
如果root
是您域中的基本路徑,例如example.com/root
,那么如果您位於example.com/root/store/products/details.php
,則將具有如下所示的鏈接以獲取根目錄。 該href
實際上可以在任何頁面上使用。 如果您使用../../index.php
,它將僅在某些頁面上有效。
<a href="/root/index.php">Root</a>
這就是我使所有模板鏈接都可移植的方式。
對於在服務器端處理的文件,您將使用SERVER_ROOT
進行鏈接,對於-a href = ...'中的鏈接,則將使用SITE_ROOT
。
define('SERVER_ROOT', dirname( __FILE__ ) . DS);
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ?
'https://' : 'http://') . $_SERVER['SERVER_NAME'];
if (strlen( $url ) <= 10) $url = null; // For IDE Support
define( 'SITE_ROOT', $url . DS); // The base URL
所以要實現以上
<a href="<?=SITE_ROOT?>example/morestuff/">Post Score</a></li>
使用<a href="../../index.php">
var base = 'https://example.com/store/products/details.php' var relative = '../../index.php' var target = new URL(relative, base).toString() console.log(target)
PHP默認為index.php,因此您可以鏈接到<a href="/root/">Link text</a>
通過在URL前面加上/(例如“ / root /”而不是“ root /”),您將強制其從Web主機的根目錄或VPS讀取網站目錄。
如果您自定義DirectoryIndex
,則可以進行<a href="/root/<Your Directory Index>.php">Link</a>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.