0

Description:

I often run into this problem when I have a website located in /var/www/ that grows way too large, and decide to move, essentially all of it, to /var/www/main_files. Simply putting a symbolic link /var/www/index.html pointing to /var/www/main_files/index.html does not work. I believe the reason it does not work is because the index.html file is still be "executed" in the directory of the symbolic link (/var/www). Therefore, any files which need to be included/fetched, will no longer have the correct paths.

One could change the VHost directory to /var/www/main_files, but that is too permanent. I may still want to have a few files in /var/www. I could also go through and manually change any file paths in the actual html/php/js files, but that is not only too permanent, it is painstakingly slow.

Question:

Is there a way, short of using mod_rewrite (which, again, is too permanent), to instruct Apache to follow symbolic links (assume symlinks are all within docroot) and, when the user goes to www.example.com/index.html, load the web page as if the user had gone to www.example.com/main_files/index.html? If not, then what other options should I consider?

Motivation:

I most often run into this problem when I want to debug a site, and I quickly download a free template (ie download this one). Most of these templates have all their files in the top folder, making it very messy to dump it all to /var/www, especially with more than one template. What I want is to make a subfolder for the template, but still be able to load it from www.example.com/index.html, not explicitly from www.example.com/template1/index.html

puk
  • 16,318
  • 29
  • 119
  • 199

1 Answers1

2

The instruction to follow symlinks is not part of the mod_rewrite, but is in the core of Apache

To enable the feature you must add FollowSymLinks to the Options directive:

  <Directory /usr/local/httpd/htdocs>
    Options Indexes FollowSymLinks
  </Directory>

See http://httpd.apache.org/docs/2.2/mod/core.html directive.

lrosa
  • 200
  • 2
  • 9
  • But will apache follow any symlinks? for example what if I set a symlink pointing to /home/foo/bar/index.html? (thanks btw) – puk Apr 10 '12 at 06:28
  • Are you sure this does what I want? I only ask because I have had the following all along `Options -Indexes +FollowSymLinks` – puk Apr 10 '12 at 06:31
  • If you just need to redirect a file within the documentroot, you can use mod_rewrite; if you want to use symbolic links, you need to enable them with Options. Probably you do not need symlinks, but just a rewrite rule, see http://stackoverflow.com/questions/990392/htaccess-rewrite-to-redirect-root-url-to-subdirectory – lrosa Apr 10 '12 at 20:15
  • Either you don't understand what I need, or I am not properly interpreting your advice. What I want is to be able to take a website template, save it to `/var/www/a/b/c/d/.../z/` then set a symbolic at `/var/www/index.html` to `/var/www/a/b/c/d/.../z/index.html` and have the website work without broken links or me having to go change all remote paths to global paths. – puk Apr 10 '12 at 20:55