How many htaccess files should i have?

Zack

New member
Joined
Jan 11, 2017
Messages
164
Points
0
I was looking at some information on .htaccess files and some things that can be done with them but I am not sure if all of the things that I have been thinking about doing with them can be done with just one .htaccess file or if there should or can be multiples.

Does anyone know how many .htaccess files should i have?
 

vishwa

Well-known member
Joined
May 12, 2014
Messages
1,096
Points
63
You can only create one .htaccess file for a website. This is the rule. because file manager do not allow you to create multiple .htaccess files. If you create multiple than it will overwrite your existing file.
 

Zack

New member
Joined
Jan 11, 2017
Messages
164
Points
0
You can only create one .htaccess file for a website. This is the rule. because file manager do not allow you to create multiple .htaccess files. If you create multiple than it will overwrite your existing file.
I saw someone saying something about multiple htaccess files and wasn't sure what they meant. I thought they might have meant multiple versions like updates.

You can have 1 htaccess file per folder on your website. You can have 1 in the root public_html folder and 1 in each sub folder and sub folder of a sub folder etc.
So as long as they are in separate folders then you can have a different one for each folder?
 

Nikita Patil

New member
Joined
Feb 20, 2017
Messages
2
Points
0
You can upload only 1 htaccess file. .htaccess file is a configuration file used by Apache-based web servers that control access of web crawlers.
 

postcd

New member
Joined
Jul 8, 2012
Messages
35
Points
0
Have as many .htaccess as you require. I think there is no limit.
.htaccess in subdirectories can override RewriteRules of the parent directory .htaccess. Just add line: "RewriteEngine On" in "child" .htaccess to do so.

/home/john/public_html/.htaccess < parent / root folder of the web
/home/john/public_html/admin/.htaccess < child / subfolder
 
Last edited:

Zack

New member
Joined
Jan 11, 2017
Messages
164
Points
0
Zack
I've seen that and didn't know what it meant. Basically it just means that the code below overrides whatever code is in the parent folders?
 

postcd

New member
Joined
Jul 8, 2012
Messages
35
Points
0
Zack: It will override only rewrite rules (RewriteRule, RewriteCond) of your parent htaccess. I am not aware of any method that would stop inheriting everything from parent htaccess.
 

Gh0st4unt3r

New member
Joined
Feb 4, 2017
Messages
67
Points
0
htaccess is very powerful when used properly and has a lot of action you can do from site optimization to website access etc.

Most sites use mainly 1 at the root to cater for all sub folders then an additional ones would be made to protect certain directories like a secure downloads folder to a members only or staff only area.

have a bit of a research on how to use them as they are very useful.

As a note you are never restricted to just 1 per site its actually 1 per folder and it will cater for all sub directories unless another one is put in place to override its parent directory settings.
 

Mike001

New member
Joined
Apr 27, 2016
Messages
578
Points
0
Listen to Rob above, he has it explained perfectly.

This is a question that comes up frequently in my college classes and I could not have explained it better and more succinct then Rob just did.

Don't make your web development life more difficult then it needs to be.

One in the public_html folder, this will pertain to all folders that do not have their own .htaccess and as Rob recommended for security reasons and file access limitations if you have a membership site, one in the members folder. This will normally have different configuration commands then the root folder based on what your members are allowed to do.

Do some reading on these file types. There are a lot of commands that can be included in the .htaccess file, many more than most people realize. Just remember test them before you upload them to a live site because with all that power, and they can be quite powerful, you can do a lot of damage, not physical but access wise, to your site if you do not understand the proper use of the commands.

Great explanation Rob.
 

hostguy

New member
Joined
Sep 25, 2021
Messages
16
Points
1
You can use only 1 .htaccess file in 1 folder, so that you can manage redirection, cache etc from .htaccess file.
 
Newer threads
Replies
5
Views
2,463
Replies
6
Views
2,166
Replies
10
Views
2,432
Latest threads
Replies
1
Views
32
Replies
1
Views
29
Replies
2
Views
42
Replies
3
Views
31
Recommended threads
Replies
2
Views
1,605
Replies
2
Views
1,659
Replies
2
Views
2,383

Referral contests

Referral link for :

Sponsors

Popular tags

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top