Reputation: 825
I have a header file which has the html <head>
tag in it. I'm trying to set the <base href="/mysite/">
in this file, but when I include it (such as into my index.php file), it doesn't actually change my base href. Any absolute URLs in index.php (e.g. /css/style.css
) try to load from host/css/style.css
rather than hosthost/mysite/css/style.css
. It seems like it doesn't actually change the base when I'm using an included PHP file. Any ways to solve this issue without having to go back and hardcode every URL?
Thanks
index.php file
<?php
include('_includes/inc_header.php');
inc_header.php file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="/mysite/html/" />
<link rel="stylesheet" href="/css/style.css" media="screen"/>
The stylesheet doesn't load and view source reveals it is trying to load from host/css/style.css
rather than host/mysite/css/style.css
Upvotes: 1
Views: 5480
Reputation: 86805
You need to remove the opening slash so the path should be css/style.css
Notice that the base path already includes the trailing slash. You should also put the full URL in the base attribute, not just the directory -
<base href="http://www.mydomain.com/mysite/html/" />
If you can't change the links, you'll have to either set the document root to that directory or set up a virtual host.
Upvotes: 1
Reputation: 1700
you can setup a virtual host in your webserver that points to /mysite/ as the root of the site.
Upvotes: 1