Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 17 Oct 2019, 20:12
alfuzzy alfuzzy is offline
 
Join Date: Jul 2018
htaccess File Help

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
Reply With Quote
  #2  
Old 18 Oct 2019, 03:37
final kaoss final kaoss is offline
 
Join Date: Apr 2006
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.
Reply With Quote
  #3  
Old 18 Oct 2019, 16:11
alfuzzy alfuzzy is offline
 
Join Date: Jul 2018
Originally Posted by final kaoss View Post
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
Reply With Quote
  #4  
Old 18 Oct 2019, 17:15
Dave Dave is online now
 
Join Date: Jun 2010
Real name: Dave
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.
__________________
https://technidev.com - security, development, exploits, vBulletin
dave[at]technidev[dot]com

Contact me for custom vBulletin 3/4 work & server/website management.
Reply With Quote
  #5  
Old 18 Oct 2019, 18:10
alfuzzy alfuzzy is offline
 
Join Date: Jul 2018
Thanks Dave. Some followup questions:

Originally Posted by Dave View Post
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?

Originally Posted by Dave View Post
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)?

Originally Posted by Dave View Post
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
Reply With Quote
  #6  
Old 18 Oct 2019, 18:22
Dave Dave is online now
 
Join Date: Jun 2010
Real name: 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.

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/curren.../htaccess.html
__________________
https://technidev.com - security, development, exploits, vBulletin
dave[at]technidev[dot]com

Contact me for custom vBulletin 3/4 work & server/website management.
Reply With Quote
  #7  
Old 18 Oct 2019, 18:32
alfuzzy alfuzzy is offline
 
Join Date: Jul 2018
Thanks again Dave.

Originally Posted by Dave View Post
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.

Originally Posted by Dave View Post
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.
Reply With Quote
  #8  
Old 18 Oct 2019, 19:51
Dave Dave is online now
 
Join Date: Jun 2010
Real name: Dave
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/...iles--net-4757
__________________
https://technidev.com - security, development, exploits, vBulletin
dave[at]technidev[dot]com

Contact me for custom vBulletin 3/4 work & server/website management.
Reply With Quote
  #9  
Old 18 Oct 2019, 21:37
alfuzzy alfuzzy is offline
 
Join Date: Jul 2018
Awesome. Thanks for the links Dave.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


New To Site? Need Help?

All times are GMT. The time now is 18:08.

Layout Options | Width: Wide Color: