Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load .htaccess From Root Directory

So I am creating a template system that is the same across multiple sites, the only thing that changed is the configuration file. I am making so all the files are getting fetched from the root directory. I can do it with all my php and html files, but I can't see to figure it out on my .htaccess file. How the directory is set up is /home/user_name/template and then there are also folders like /home/user_name/site1.com and all off the sites. So how can I make all of the site use the same .htaccess file. I hope that makes sense!

like image 214
Nico Plyley Avatar asked Mar 15 '23 20:03

Nico Plyley


2 Answers

According to Wikipedia

A .htaccess (hypertext access) file is a directory-level configuration file supported by several web servers, that allows for decentralized management of web server configuration. They are placed inside the web tree, and are able to override a subset of the server's global configuration for the directory that they are in, and all sub-directories

From Oracle-Docs :

If you enable .htaccess files, the server checks for .htaccess files before serving resources. The server looks for .htaccess files in the same directory as the resource and in that directory's parent directories, up to and including the document root.

For example,

if the Primary Document Directory is set to /oracle/server/docs

and a

client requests /oracle/server/docs/reports/index.html,

the server will check for :

.htaccess files at /oracle/server/docs/reports/.htaccess and /oracle/server/docs/.htaccess.

suppose you have 2 sites and you want to setup .htaccess for both your both sites using a single file

then just create the file structure like following

  • parent
    • site1
    • site2
    • .htaccess

Here upload all data of site1 into the site1 folder and so on.

like image 88
alamin Avatar answered Mar 21 '23 15:03

alamin


If the server is a linux/posix system, you can create a symbolic link to the root .htaccess file. This should be something like

cd /home/user_name/site1.com
ln -s ../template/.htaccess .

Beware the file permissions, so only you can write to it.

like image 38
Leonardo Brugues Avatar answered Mar 21 '23 15:03

Leonardo Brugues