a little issue with including a file

Discussion in 'HTML & Website Design' started by asmon, Dec 30, 2010.

  1. #1
    I have the following issue.
    for user's comfort, i am using RewriteEngine (.htaccess)
    so instead of showing the following
    "http://localhost/index.php?display=subject&id=15"
    it's actually "http://localhost/subj/15"

    The problem comes when i am trying to insert stylesheets.
    when i put
    "<link rel="stylesheet" href="stylesheets/main.css" type="text/css" /> "
    Code (markup):
    then it works for the main page which is just "http://localhost"
    but it doesn't work on the subjects page, i have to add
    <link rel="stylesheet" href="[B]..[/B]/stylesheets/main.css" type="text/css" /> 
    Code (markup):
    and then it doesn't work for the main page.. it considers "/subj/"
    as a sub folder... how can i make it work for both scenarios?
    it used to be fine on a different server but on my local machine it causes this issue... i don't think i can define a "root_path" like i do it with php..
     
    asmon, Dec 30, 2010 IP
  2. IAreOwn

    IAreOwn Active Member

    Messages:
    46
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    95
    #2
    why not just use the complete url path of the css...

    eg

    
    <link rel="stylesheet" href="http://site.com/stylesheets/main.css" type="text/css" />
    
    HTML:
    or just store it on a php variable

    
    <link rel="stylesheet" href="<?=$root?>/stylesheets/main.css" type="text/css" />
    
    PHP:
     
    IAreOwn, Dec 30, 2010 IP
  3. jkl6

    jkl6 Peon

    Messages:
    70
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The problem is that you are referencing a relative path. Use absolute path like this:
    <link rel="stylesheet" href="/stylesheets/main.css" type="text/css" />
    Note the "/" before stylesheets and make sure stylesheets is a directory at the root html level.
     
    jkl6, Dec 30, 2010 IP