Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple htaccess files in one folder, or conditional AuthType Basic?

I am using the same .htaccess file on my local, and live servers, and want to use the same file on my test server (to made code management easier).

Currently though I have to have a different file, because my test server has htaccess password access on it, AuthType Basic.

Is there a way to either have 2 .htaccess files in the same folder (different names of course) - so that I can add the extra file on the test server, or, somehow make the AuthType conditional based on where it is, ie in a certain folder or under a certain http host? This way the same file can be used but it will act differently depending on where you are viewing it from.

Help and advice much appreciated.

like image 801
Newmania Avatar asked Jun 23 '10 12:06

Newmania


People also ask

Can you have multiple .htaccess files?

You can have more than one . htaccess file on your hosting account, but each directory or folder can only have one. For example, you can have separate . htaccess files in your root folder and another in a sub-folder.

What should htaccess file permissions be?

File permissions for . htaccess should be set to 755 . There should be a “File Permissions” option in your FTP client. Alternatively, you can run the command chmod 755 .

Where do I put .htaccess file?

You can put your . htaccess in the top level directory and have it apply settings to specific subfolders.

What is IfModule in htaccess?

<IfModule> is simply a directive that tests the condition "is the named module loaded by apache httpd" (in your example mod_expires). It allows people to produce conditional based configuration for different installations where certain modules may be present or not.


1 Answers

One way would be to configure a different AccessFileName on the development server, e.g. htaccess.dev.

In httpd.conf (or similar - depending on your distro):

AccessFileName htaccess.dev

Then add both files in the directory - the htaccess.dev should be only interpreted on the development server.

You can also set AccessFileName per <VirtualHost />.

There are a way to do multiple AccessFileName directives:

AccessFileName .htaccess.first .htaccess.second .htaccess

I'm not exactly sure which is parsed first, but I imagine the last one wins, meaning it's probably .first, .second and then .htaccess and whatever is in the last one is the active setting.

like image 99
Till Avatar answered Oct 26 '22 23:10

Till