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.
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.
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 .
You can put your . htaccess in the top level directory and have it apply settings to specific subfolders.
<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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With