7
4

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.

trailing slash(URL末尾の"/")と相対URL

Last updated at Posted at 2018-09-09

当たり前かもしれないけど、結構差が出るなぁ、と思って確認しました。

trailing slash(トレイリングスラッシュ)は、URL末尾の"/"のことで、
(特に動的ページの場合に)設計の時に付けるか付けないかで迷ったりします。

/home/hello/内では、相対URL./home/hello/(自分)のことを指します。
(まぁ本来ディレクトリなことを考えると当然と言えば当然?)

一方で、/home/hello内では、相対URL./home/(親)のことを指します。

だとすると、トレイリングスラッシュなしだと、自分に相対URLでリンクしようとすると、
いちいち./{そのページの名前}としなければならないので、
トレイリングスラッシュありの方が、REST風URLにした時とかに、GETでフォームが表示されて、それにPOSTしたりする時に便利な気がします。

表にまとめてみると以下のようになります。

自分のパス .が表すパス 自分への相対パス
/home/hello/ /home/hello/ (自分) .
/home/hello /home/ (親) ./hello

(こういう視点で指摘されているのを見たことない気がするのですが、当たり前だから言及されてないだけなんですかね?)

(Laravelだとトレイリングスラッシュなしなので、どうしようかなぁ。)

7
4
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
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?