2017-02-15 21 views
0

我有2個文件的目錄中它的HTML瀏覽到同一目錄

http://domain.com/folder/index.phphttp://domain.com/folder/page.php

在索引頁,我試圖讓一個重定向到http://domain.com/folder/

,如果我做一個鏈接像這樣的鏈接

<a href="#">Go to Index</a> 

它不會刷新頁面,如果我保持它爲空這

<a href="">Go to Index</a> 

它會得到任何頁面上的鏈接,我在同一個文件夾。如果我在這裏http://domain.com/folder/page.php該鏈接就會像

<a href="http://domain.com/folder/page.php">Go to Index</a> 

那我該怎麼做一個鏈接到索引頁再次而不是我放的index.php?

+0

你可以用'在href參數/ folder'。另一件事是你可以使用meta base標籤來指定你的'folder'的根文件夾,然後你可以在你的href參數中使用'/'。 https://www.w3schools.com/tags/tag_base.asp – tilz0R

+0

@ tilz0R我怎麼沒有親愛的? –

回答

0

你有兩個選擇:

您可以使用相對鏈接:

<a href="./page.php">Go to page.php</a>

,或者如果你在page.php文件

<a href="./">Go to index.php</a>

這將查看您要更改頁面的包含文件夾。


您可以使用像@根路徑tilz0R建議,並聲明 base href

//on index.php 
<head> 
    <base href="http://domain.com/folder/" target="_blank"> 
</head> 
//on page.php: 
<a href="/">Go to Index</a> 
+0

親愛的,但我不想使用「index.php」 –

+0

@MmPp請參閱更新 – Zze