Symbolic links (symlinks) are an extremely useful tool to every system admin and web application developer. They work a lot like a shortcut in Windows. Let’s say you were working with a web application that used a framework that held all Javascript, CSS and image files in a tucked-away location (for the sake of this example, that location is /var/www/html/production/clientside/, making /var/www/html/production/clientside/js/ the location of the Javascript files). And you, the developer working on creating these Javascript, CSS and image files, wanted to use /js/somefile.js instead of a longer name like /production/clientside/js/somefile.js in your public-facing code. To do this, use the following commands:
ln -s /var/www/html/production/clientside/js/ /var/www/html/js/
ln -s /var/www/html/production/clientside/css/ /var/www/html/css/
ln -s /var/www/html/production/clientside/images/ /var/www/html/images/
Bear in mind that if you are using a framework that has pretty URL rules in the .htaccess file, you will have to make exclusions (below is the basic /var/www/html/.htaccess in our example framework):
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css|js)
RewriteRule ^(.*)$ /index.php/$1 [L]
Leave a Reply