Forum Moderators: phranque

Message Too Old, No Replies

htaccess rewrite for paths

         

Omzy

12:09 am on Oct 30, 2009 (gmt 0)

10+ Year Member



I am running Apache on Windows. My DocumentRoot is:

C:/apache/web sites

The site is at:

C:/apache/web sites/mysite/index.php

In index.php there is a common include file (header.php) with a stylesheet link as follows:

<link rel="stylesheet" type="text/css" href="styles.css" />

So far so good. But I have a directory within "mysite":

C:/apache/web sites/mysite/advertising/index.php

Again in index.php there is the include file, but obviously the style sheet reference is pointing to the current folder.

I tried changing the path of the stylesheet link to "/styles.css" and "../styles.css" but this obviously will give the root file an invalid path.

How can I satisfy both conditions? Do I have to specify a RewriteBase or something?

g1smd

12:35 am on Oct 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Includes work within the filesystem and should use internal server filesystem folder names to specify the location.

Style sheets work within a URL structure and should use references relative to server root as seen from the web.

jdMorgan

1:39 am on Oct 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> I tried changing the path of the stylesheet link to "/styles.css" [...] but this obviously will give the root file an invalid path.

That *will not* give an invalid path, because it specifies that this path starts at "root," so it's likely that you didn't completely flush (delete) your browser cache before testing...

Jim

Omzy

10:01 am on Oct 30, 2009 (gmt 0)

10+ Year Member



Yes, and "root" in this case would be C:/apache/web sites/

But I want the stylesheet reference to always resolve the styles.css file in the folder C:/apache/web sites/mysite/

Omzy

10:02 am on Oct 30, 2009 (gmt 0)

10+ Year Member



Yes, and "root" in this case would be C:/apache/web sites/

But I want the stylesheet reference to always resolve the styles.css file in the folder C:/apache/web sites/mysite/

jdMorgan

1:44 pm on Oct 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Then either link to "/mysite/styles.css", correct the code that "maps" mysite.com to the /mysite server filepath so that it correctly handles css files as well as the ones it currently handles, or fix your DocumentRoot to point to the correct filepath. Which you choose depends on your current set-up -- I can't tell what you're doing 'behind the scenes' to map domains to filepaths, and so cannot make a more specific recommendation.

Jim

Omzy

6:38 pm on Oct 30, 2009 (gmt 0)

10+ Year Member



Then either link to "/mysite/styles.css"
I can't coz I need this to work on both localhost and the live server

or fix your DocumentRoot to point to the correct filepath
I can't coz I need to run multiple sites under the document root, for example: C:/apache/web sites/mysite and C:/apache/web sites/mysite2

g1smd

8:53 pm on Oct 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



One line of PHP could detect which server you are on and write the correct link out to the page.