0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

URLの最後の/のあるなしでカレントの位置が異なる

Last updated at Posted at 2015-04-14

考えてみれば当たり前だけど、念のためめも

カレントは一番最後のスラッシュのあとになるため、相対パスを使うときは注意する

リンクをhoge.htmlと書いた場合に、URLの/のあるなしで指しているパスが異なる

例えば、aタグで書いたり

<a href="hoge.html">hoge</a>

ajaxで書いた場合、

$.get(hoge.html)

以下のようになる。

1.カレントのURLの最後にスラッシュがないパターン

現在のURL http:://foo/bar
絶対パス http:://foo/hoge.html

2.カレントのURLの最後にスラッシュがあるパターン

現在のURL http:://foo/bar/
絶対パス http:://foo/bar/hoge.html

3.カレントのURLにクエリストリングがあるパターン

現在のURL http:://foo/bar?fuga=12345
絶対パス http:://foo/hoge.html

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?