Jump to content

[SOLVED] htaccess rewrite for paths


Omzy

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/179559-solved-htaccess-rewrite-for-paths/
Share on other sites

What folder is styles.css in? The first example of things you've tried looks closest. The preceding slash will take you to document root, you then make the path relative to there. If you wish to make the code portable, your best option will be to stick with the preceding slash and to set-up a virtual host on Apache to change the document root. You can find a basic tutorial I wrote a while back here.

There are a couple of options. You can use $_SERVER['DOCUMENT_ROOT'], you can use __FILE__ to make paths relative to the actual file not the file it's included in, you can define('DOC_ROOT', 'http://localhost/mysite') in a settings file and include that file in every top level script, you can make all paths relative to the file they are in, you can use the method I suggested before to set the document root accurately on localhost, it might be possible to set localhost/mysite as a virtual host, I'm not entirely sure having never tried, but seems unlikely you could have a forward slash in a domain.

 

I will point out that live 'shared' hosting will probably give you different results to dedicated hosting, depending on how it's set up.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.