フルパスを書かずに同じまたは異なるフォルダにある場合、どうすればhtmlページにリンクできますか?
14 に答える
同じフォルダー内で、次のファイル名を使用します。
<a href="thefile.html">my link</a>
親フォルダーのディレクトリ内:
<a href="../thefile.html">my link</a>
サブディレクトリ内:
<a href="subdir/thefile.html">my link</a>
また、これはディレクトリを上に移動してから、別のサブフォルダに戻ります。
<a href = "../subfolder/page.html">link</a>
複数のディレクトリを上に移動するには、これを行うことができます。
<a href = "../../page.html">link</a>
ルートに行くために、私はこれを使用します
<a href = "~/page.html">link</a>
さらに、ルート ディレクトリを参照する場合は、次を使用できます。
/
これはルートを参照します。したがって、いくつかのレベルのフォルダー内にネストされたファイルにいて、メインの index.html に戻りたいとします。
<a href="/index.html">My Index Page</a>
ロバートは、さらに相対パスの説明を行っています。
を使用して、階層内のフォルダーを上に移動できます
../
したがって、/webroot/site/pages/folder1/myotherpage.htm からフォルダー /webroot/site/pages/folder2/mypage.htm に移動するには、リンクは次のようになります。
<a href="../folder2/mypage.htm">Link to My Page</a>
相対パスを使用する
メインページは次のようになります: /index.html
セカンダリ ページ: /otherFolder/otherpage.html
リンクは次のようになります。
<a href="/otherFolder/otherpage.html">otherpage</a>
ルートディレクトリにリンクしたい場合は、使用できます
/
、 また/index.html
同じディレクトリ内のファイルにリンクしたい場合は、単にファイル名を入力してください
<a href="/employees.html">Employees Click Here</a>
フォルダを戻すには、次を使用できます
../
ルート ディレクトリから employees ディレクトリのインデックス ページにリンクするには、次のようにします。
<a href="../employees/index.html">Employees Directory Index Page</a>
I would caution you: if you are using absolute paths, then your application cannot be installed in a "subdirectory" of the server!
eg, http://yourserver.com/yourapp may work, but http://myserver.com/apps/yourapp will not!
これは私のために働いた<a href="preferedfile name.html">to be clicked <a/>