Search code examples
htmlapachewebvhostsdocument-root

Apache: change document root for directory in site


I'm coding a portfolio website, and one portion of my website is past works. I have an archived version of a website I developed that is no longer online. I would like it so that 8 can view the site at mydomain.com/work/nameofoldsite.

I just uploaded the archive of the old site to the work folder on my portfolio site, but as it stands now, I would have to alter every page. All links on the site are absolute paths, but the root directory is different on the new portfolio than on the original site. E.g. A picture that was once at /files/img.jpg now needs to be /work/nameofoldsite/files/img.jpg.

What is the best way to put this old website inside of my new portfolio site without altering all of my code? Can I simply change the perceived document root for the /work/nameofoldsite directory?


Solution

  • If your site was in pure HTML, you could change all the href by replace all "/files" to "/work/nameofoldsite/files" in any text-editor

    You can also write an .htaccess if you run apache (with mod rewrite enabled) that would looks like :

    RewriteEngine On
    RewriteRule ^files/(.)*$ /work/nameofoldsite/files/$1 [L,QSA]
    RewriteRule ^anotherfolderyouwanttomove/(.)*$ /work/nameofoldsite/anotherfolderyouwanttomove/$1 [L,QSA]
    

    but modRewrite can go wrong very quick

    Or if you use a CMS, there should in the administration a place where you can set the root of the CMS