Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I test a website in my local installation of Apache I always have /<site files> as the path. When the site gets deployed the root path will be just /.

Because I need to use absolute referencing I have to use / on localhost and then change it everywhere for the remote server to simply /.

How can I please do that better? Can I set something in .htaccess for this?

share|improve this question

Put this in your .htaccess (in /):
RewriteEngine On
RewriteRule ^/*)$$1 [R=301]

If that doesn't work, replace the ^/mysite with ^mysite (I can't remember offhand where it starts matching).

share|improve this answer
Hi, thanks for the reply. I'm not sure I was clear. What I want is for my local installation of Apache, when accessing: localhost/mysite which normally has this absolute path /mysite/ to set the root for localhost/ to be simply /, in order to match how it will be when deploied. – Francisc Nov 8 '10 at 22:57
Can you give a more specific example? Is it the DocumentRoot (ie. where abouts on the server the files are stored) that needs changing? If so, change this inside Apache or rewrite them as above. If not, I'm not sure I understand – James L Nov 9 '10 at 0:51
Ok, I want to have the root set to /mysite/ for localhost/mysite. – Francisc Nov 9 '10 at 11:22
For /mysite/index.php if I want to load this image I have to use /mysite/img.jpg. However what I want is to point to the image when the call is made from /mysite/index.php like this /img.jpg as if it would be in the root. I want for /mysite/index.php to have the root inside /mysite/. – Francisc Nov 9 '10 at 11:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.