moving from document_root to subdirectory

Using a single web hosting account to host multiple sites

moving from document_root to subdirectory

Postby bartezz » Wed Jun 11, 2008 8:04 am


I have to move a website that is currently hosted within the www root ($_SERVER['document_root']) of the hosting package to a subdirectory. Problem being that the scripting and the content of this website relies on the website being in the www root. Some urls used are relative to $_SERVER['document_root'] some urls used are hardcoded all over...

I thought my best option was to reset the PHP_FLAG $_SERVER['document_root'] via a htaccess to var/users/www/subdirectory/ but I don't think this is possible.

So now I'm thinking of placing an htaccess with a mod_rewrite. But I'm a newbie to this. I'll explain in PHP code what I'd like to do;

Code: Select all
if(!ereg(^"subdirectory", $_SERVER['DOCUMENT_ROOT'])) {
   $_SERVER['DOCUMENT_ROOT'] = "subdirectory/".$_SERVER['DOCUMENT_ROOT'];

Hope you guys get what I mean... :) Am very tired at this point :p

Cheers and thanx for ur time!
Posts: 2
Joined: Wed Jun 11, 2008 7:53 am

Postby richardk » Wed Jun 11, 2008 2:54 pm

Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Add missing trailing slashes.
RewriteCond %{DOCUMENT_ROOT}/subdirectory%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

RewriteRule ^(.*)$ /subdirectory/$1 [QSA,L]
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby bartezz » Thu Jun 12, 2008 1:46 am

Hi Richard,

Thanx for the reply. I ended up fixing it all in another way but I know I'll be encountering this more often so thanx for the code!

Posts: 2
Joined: Wed Jun 11, 2008 7:53 am

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 3 guests