013231
V2EX  ›  问与答

URL末端是否帶有'/'導致相對路徑變化, 怎樣解決比較好?

  •  
  •   013231 · Jun 18, 2012 · 2991 views
    This topic created in 5085 days ago, the information mentioned may be changed or developed.
    http://hostname/subdir

    http://hostname/subdir/
    都打開同一個網頁(http://hostname/subdir/index.html), 但是以這兩種方式打開時, 網頁中相對路徑的意義卻不同:
    以第一種方式打開時, 網頁中的"./base.css"是指"http://hostname/base.css";
    以第二種方式打開時, 網頁中的"./base.css"是指"http://hostname/subdir/base.css".
    於是導致各種404.
    這個問題怎樣解決比較好?
    5 replies    1970-01-01 08:00:00 +08:00
    binux
        1
    binux  
       Jun 18, 2012   ❤️ 1
    301到正确的那个
    kamwing
        2
    kamwing  
       Jun 18, 2012
    直接在页面引用绝对路径的css就可以了, 没必要纠结这个吧。
    caoyue
        3
    caoyue  
       Jun 18, 2012
    用根目录,不用父目录
    Sunya
        4
    Sunya  
       Jun 18, 2012
    http://www.sinzi.org/urls-structure-optimization/

    如果是从SEO方面去考虑,建议加 "/", 另外再统一下路径。
    mitnk
        5
    mitnk  
       Jun 18, 2012
    不要用相对路径(./main.css)。

    任何地方都用绝对路径:
    /media/css/main.css
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5244 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 08:18 · PVG 16:18 · LAX 01:18 · JFK 04:18
    ♥ Do have faith in what you're doing.