Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess or symbolic link (symlink)

Tags:

I have a website with multiple folders and I was trying to fix them in my .htaccess. After a little while, I have a big .htaccess with rules that conflicts.

Now every time I want to add a folder I have to add it to the .htaccess.

I did some research and I found out I can create symbolic link instead, so no more .htaccess

In both solution I have to create or modify something so for me its the same result at the end but is it a better practice to create instead symbolic link ?

like image 270
Adam Avatar asked Dec 09 '11 12:12

Adam


People also ask

Why should one use a symbolic link?

Why use symbolic links? You can operate on symlinks as if they were the actual files to which they pointing somewhere down the line (except deleting them). This allows you to have multiple "access points" to a file, without having excess copies (that remain up to date, since they always access the same file).

Is symbolic link same as soft link?

A symbolic link, also termed a soft link, is a special kind of file that points to another file, much like a shortcut in Windows or a Macintosh alias. Unlike a hard link, a symbolic link does not contain the data in the target file. It simply points to another entry somewhere in the file system.

When would you need a symbolic link?

Symbolic links are used all the time to link libraries and make sure files are in consistent places without moving or copying the original. Links are often used to “store” multiple copies of the same file in different places but still reference to one file.

Can you chain symlinks?

Yes. You can only stack so much symbolic links together before the kernel and/or application refuse to follow the chain.


2 Answers

Symbolic links are faster yes (like Aki said) but here's my thoughts on this.

if you have images, css or js files then you don't need to rewrite or create symbolic links. You can use the full URL (eg /images/...) or use a common domain like i.domain.com (or anything you want) and refer all your JS, Images and CSS there. Eg: i.domain.com/logo.jpg or js.domain.com/site.js.

This way, you never have to think about rewriting rules or create links you might forget one day.

This one is very easy to manage and maintain if you need to add images, change js or update your CSS since you only have one point of entry and automatically everything be updated.

like image 172
Book Of Zeus Avatar answered Sep 20 '22 19:09

Book Of Zeus


use symblink, .htaccess has to be proccesed by apache whereas the symblink are proccess by the OS which is faster.

creating 100 rules vs 100 symblink, if the rule you looking for is at the last you will have to parse all of them then use the one you need.

like image 36
aki Avatar answered Sep 17 '22 19:09

aki