tags:

views:

38

answers:

2

Hi,

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"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<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

+1  A: 

you can setup a virtual host in your webserver that points to /mysite/ as the root of the site.

burntblark
I went ahead and did this.. Thanks
Lincecum
+1  A: 

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.

Eran Galperin
Is there a way to do it without having to change every link? This is a server copy I'm trying to run locally, so I don't want to change all the links.
Lincecum
Basically all I want is to change the root path to refer to the folder for this website rather than the server root. (localhost/mysite/ rather than localhost/)
Lincecum
If all the links already include the trailing slash, you need to set the document root to that folder or set up a virtual host. There's no way around it
Eran Galperin