简体   繁体   中英

File don't get attached when I use absolute path in HTML CSS

I was using PHP include function to include the header and footer but now I want to change location of my files so I created a folder named admin panel and created a PHP file in it. Now I want to connect my header.php file using include but all the path in header file are give in reference so I want to change it to absolute path but when I change it then it doesn't work.

The reference file path is given like this:

<link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all">

Now when I change it to absolute then it dont work

<link href="/home/username/public_html/css/bootstrap.css" rel="stylesheet" type="text/css" media="all"> 

I am having GoDaddy hosting so this is the way to add absolute path in GoDaddy they say. This is GoDaddy's answer link: https://in.godaddy.com/help/what-is-my-absolute-path-16023

If I am doing something wrong then please tell me thanks in advance.

Best way for you is to get the absolute path through php, so you have no doubt. And to get that just use this

<?php
$path = getcwd();
echo "The absolute Path is ".$path;
?>

Suppose you site is www.example.com and you are giving the absolute path like /home/username/public_html/css/bootstrap.css it will search at http://www.example.com/home/username/public_html/css/bootstrap.css but if you give like /css/bootstrap.css it will search at http://www.example.com/css/bootstrap.css . if there is a forward slash at the beginning.

If you use a forward slash at the beginning of your path, the path will start in your root folder.

Like this:

<link href="/css/bootstrap.css" rel="stylesheet" type="text/css" media="all">

This path should work in any file in any directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM