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,137
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.
 

Rob Whisonant

Moderator
Joined
May 24, 2016
Messages
2,481
Points
113
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.
 

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?
 

Rob Whisonant

Moderator
Joined
May 24, 2016
Messages
2,481
Points
113
Rob Whisonant
Yes. Just keep in mind that an htaccess file acts on the folder it is in and any sub folders that don't have an htaccess file in them.

Don't make things difficult though. Keep it simple. The majority of sites that need htaccess only need 1 file in the root folder. If it's a membership site, then 1 in the members area folder also.
 

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.
 

Rob Whisonant

Moderator
Joined
May 24, 2016
Messages
2,481
Points
113
Rob Whisonant
This is not true. You can upload one in every folder on the website. They also control a LOT more than just control crawlers access to your site. Go search out some htaccess tutorials and study them. You will be amazed at what can be done with them.
 

postcd

Member
Joined
Jul 8, 2012
Messages
35
Points
8
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

Member
Joined
Jul 8, 2012
Messages
35
Points
8
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

Member
Joined
Feb 4, 2017
Messages
67
Points
8
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
20
Points
3
You can use only 1 .htaccess file in 1 folder, so that you can manage redirection, cache etc from .htaccess file.
 

harrygreen90

Active member
Joined
Dec 17, 2013
Messages
413
Points
28
The number of .htaccess files you should have depends on the specific needs and configurations of your website. Typically, you only need one .htaccess file for a single website. This .htaccess file is placed in the root directory of your website and can be used to control the behavior of your website, such as redirecting visitors, adding security, and managing caching.

However, in certain cases, you may want to have multiple .htaccess files for different directories within your website. For example, you may want to have different redirect rules for different parts of your website, or different security settings for different areas. In these cases, you can create separate .htaccess files for each directory, and those rules will only apply to that specific directory.

So, the number of .htaccess files you should have depends on the complexity of your website and the specific rules you want to apply to different parts of it. If you only have a few simple rules, one .htaccess file may be sufficient. If you have more complex needs, multiple .htaccess files may be necessary.
 

Lineldon

New member
Joined
Nov 2, 2022
Messages
11
Points
3
I've always used one in which I embedded code with comments in separate blocks. Why have more?
 
Newer threads
Replies
5
Views
2,928
Replies
6
Views
2,652
Replies
10
Views
3,034
Latest threads
Replies
1
Views
88
Replies
1
Views
179
Replies
4
Views
385
Replies
11
Views
527
Replies
2
Views
229
Recommended threads
Sold -
Replies
1
Views
5,898

Latest postsNew threads

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