View Full Version : htaccess File Help
alfuzzy
10-17-2019, 05:12 PM
My server setup has multiple .htaccess files (which I'm guessing may be normal).
Server setup is public_html directory...then forums sub-directory. Both the public_html directory & forums sub-directory each have a .htaccess file.
My questions are:
1. How do each of these .htaccess files work together (if they do)?
2. Should each of them contain the exact same information...or should the higher up public_html directory have less/more info...or should the lower sub-forums directory have more/less info in it?
I'm sure I will have follow up questions...but wanted to get these 2 out of the way first.
Thanks
final kaoss
10-18-2019, 12:37 AM
Basically what you need to know is that a .htaccess file in a parent directory will affect all child folders of it. So knowing this, you can set your rules as needed.
alfuzzy
10-18-2019, 01:11 PM
Basically what you need to know is that a .htaccess file in a parent directory will affect all child folders of it. So knowing this, you can set your rules as needed.
Thanks final kaoss...what you said makes sense.
Thus here are two hypothetical situations...anyone please let me know if what I'm stating makes sense (or not):
1. If an .htaccess file in a parent directory effects all child folders or directories in it. In theory..does it make sense that a child directory could have more rules or more restrictions than the parent directory?
2. In theory...could a parent & child directory have exactly the same .htaccess file rules...and everything work fine (basically both parent & child directory have exactly the same duplicated .htaccess file)?
And here's one additional question. Looking at my websites server setup...is it basically a given that almost all parent & child directories have an .htaccess file? Most of mine do...but I do see some that don't.
Thanks
1. A child directory inherits the parent .htaccess rules and you can apply additional rules to the child .htaccess file as well.
2. If the child directory has no .htaccess file then it will inherit the parent .htaccess file. However keep in mind that, depending on the rules that have been defined in the parent .htaccess file, it might not match in the child directory.
Whether or not you need a .htaccess file in all directories depends entirely on your configuration and needs.
alfuzzy
10-18-2019, 03:10 PM
Thanks Dave. Some followup questions:
1. A child directory inherits the parent .htaccess rules and you can apply additional rules to the child .htaccess file as well.
Let's say (in theory) a child directory didn't need any additional rules compared to the parent directory.
Could the child directory run properly without any .htaccess file at all...or would the child directory need it's own .htaccess file & it would look exactly the same as the parent directory .htaccess file?
2. If the child directory has no .htaccess file then it will inherit the parent .htaccess file. However keep in mind that, depending on the rules that have been defined in the parent .htaccess file, it might not match in the child directory.
Let's say the parent directory had 7 rules in it's .htaccess file...and a website owner wanted the child directory to have 3 additional .htaccess rules. Would the child directory's .htaccess file ONLY need the 3 extra rules stated...or would the child directory need to have all 10 rules stated (7 from the parent directory & the 3 additional child directory rules)?
Whether or not you need a .htaccess file in all directories depends entirely on your configuration and needs.
I know that .htaccess files can do a lot of things...I believe one of the primary things .htaccess files can do is "allow" and "deny" certain traffic into a directory based on IP address/IP address range. Where the .htaccess file is sort of acting like a doorway into the directory. Is this sort of true?
The .htaccess files for my site contain a lot of "rewrite" rules as well...which I guess I need to learn more about in general...and how they are working specifically for my site.
Thanks
Yes, the child directory can run without its own .htaccess file if it meets the parent .htaccess rules. If you add 3 rules in a .htaccess file in the child directory, it will inherit the parent rules and load the 3 additional rules.
The most popular feature of .htaccess is "RewriteRule" where if a certain condition is met, it redirects either the user or request internally to a different script or page. You can also deny access based on IP addresses like you said. The rewrite rules are commonly used for clean URL's. For example a page at example.com/category/subcategory/productname might rewrite the URL behind the scenes to example.com/index.php?route=category/subcategory/productname where the framework that runs behind the scenes parses the URL and further processes it to show the proper page.
Here is a good source for you https://httpd.apache.org/docs/current/howto/htaccess.html
alfuzzy
10-18-2019, 03:32 PM
Thanks again Dave.:)
Yes, the child directory can run without its own .htaccess file if it meets the parent .htaccess rules. If you add 3 rules in a .htaccess file in the child directory, it will inherit the parent rules and load the 3 additional rules.
I understand some of this...but get lost a little bit with the statement "If it (the child directory) meets the parent .htaccess rules".
I guess I was thinking that if the child directory didn't have it's own .htaccess file...then there would be no rules for the child directory not to meet...and thus access to the child directory would be the same as the parent directory. But then again...I guess there are all sorts of .htaccess rules...more than just access related.
Here is a good source for you https://httpd.apache.org/docs/current/howto/htaccess.html
Thanks a bunch for the link...I really want to learn more about .htaccess files & what they can & cannot do. If there are any additional good/great links...please post.:)
Thanks again.
For example the .htaccess rules in the parent directory might have a rule such as "if the URL contains /some/directory, redirect to location X" but this rule might never be met in the child directory.
Here are 2 more good sources for you: http://www.htaccess-guide.com/ and https://code.tutsplus.com/tutorials/the-ultimate-guide-to-htaccess-files--net-4757
alfuzzy
10-18-2019, 06:37 PM
Awesome. Thanks for the links Dave.:)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.