3 Replies - 4122 Views - Last Post: 14 April 2012 - 03:22 PM

#1 icedd  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 98
  • Joined: 04-March 08

Can Apache2 use 2 .htaccess files in the same directory?

Posted 22 March 2012 - 06:30 AM

My question is:
Can Apache2 use 2 .htaccess files in the same directory without conflict?


The default .htaccess file for modx CMS
# MODX supports Friendly URLs via this .htaccess file. You must serve web
# pages via Apache with mod_rewrite to use this functionality, and you must
# change the file name from ht.access to .htaccess.
#
# Make sure RewriteBase points to the directory where you installed MODX.
# E.g., "/modx" if your installation is in a "modx" subdirectory.
#
# You may choose to make your URLs non-case-sensitive by adding a NC directive
# to your rule: RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]

RewriteEngine On
RewriteBase /



# Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
#RewriteCond %{HTTP_HOST} .
#RewriteCond %{HTTP_HOST} !^example-domain-please-change\.com [NC]
#RewriteRule (.*) http://example-domain-please-change.com/$1 [R=301,L]
#
# or for the opposite domain.com -> www.domain.com use the following
# DO NOT USE BOTH
#
#RewriteCond %{HTTP_HOST} .
#RewriteCond %{HTTP_HOST} !^www\.example-domain-please-change\.com [NC]
#RewriteRule (.*) http://www.example-domain-please-change.com/$1 [R=301,L]



# Rewrite secure requests properly to prevent SSL cert warnings, e.g. prevent 
# https://www.domain.com when your cert only allows https://secure.domain.com
#RewriteCond %{SERVER_PORT} !^443
#RewriteRule (.*) https://example-domain-please-change.com.com/$1 [R=301,L]



# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]



# Make sure .htc files are served with the proper MIME type, which is critical
# for XP SP2. Un-comment if your host allows htaccess MIME type overrides.

#AddType text/x-component .htc



# If your server is not already configured as such, the following directive
# should be uncommented in order to set PHP's register_globals option to OFF.
# This closes a major security hole that is abused by most XSS (cross-site
# scripting) attacks. For more information: http://php.net/register_globals
#
# To verify that this option has been set to OFF, open the Manager and choose
# Reports -> System Info and then click the phpinfo() link. Do a Find on Page
# for "register_globals". The Local Value should be OFF. If the Master Value
# is OFF then you do not need this directive here.
#
# IF REGISTER_GLOBALS DIRECTIVE CAUSES 500 INTERNAL SERVER ERRORS :
#
# Your server does not allow PHP directives to be set via .htaccess. In that
# case you must make this change in your php.ini file instead. If you are
# using a commercial web host, contact the administrators for assistance in
# doing this. Not all servers allow local php.ini files, and they should
# include all PHP configurations (not just this one), or you will effectively
# reset everything to PHP defaults. Consult www.php.net for more detailed
# information about setting PHP directives.

#php_flag register_globals Off



# For servers that support output compression, you should pick up a bit of
# speed by un-commenting the following lines.

#php_flag zlib.output_compression On
#php_value zlib.output_compression_level 5



# The following directives stop screen flicker in IE on CSS rollovers. If
# needed, un-comment the following rules. When they're in place, you may have
# to do a force-refresh in order to see changes in your designs.

#ExpiresActive On
#ExpiresByType image/gif A2592000
#ExpiresByType image/jpeg A2592000
#ExpiresByType image/png A2592000
#BrowserMatch "MSIE" brokenvary=1
#BrowserMatch "Mozilla/4.[0-9]{2}" brokenvary=1
#BrowserMatch "Opera" !brokenvary
#SetEnvIf brokenvary 1 force-no-vary


The one I want to add...
RewriteEngine On
RewriteBase /

Options -Indexes
ErrorDocument 403 /assets/403.php


I know I could make them one. But I am making a package to setup modx the way I like it, and I can only add new files, not edit existing ones. I also, need this package incase new developers come who are not farmiliar with modx yet. There is more to it, but this is my only concern. I don't know if it will have problems with apache or not, I could not find solid info on this topic.


Resources I've found, but they weren't quite the same info, or lacked explanations.
http://www.webmaster...orum92/4606.htm
http://stackoverflow...-authtype-basic


Thanks for any help!

Is This A Good Question/Topic? 0
  • +

Replies To: Can Apache2 use 2 .htaccess files in the same directory?

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: Can Apache2 use 2 .htaccess files in the same directory?

Posted 22 March 2012 - 07:17 AM

No, I don't believe there is a way to do that. Like that SO link suggested you can use AccessFileName to specify a list of potential access files but it will only read the first file it finds that matches the list.

The server config file has a Include directive that can include other config files but it's not available to .htaccess files. I assume editing the server config file to include your second .htaccess file is not what you want?


This package you are making. Would it not be possible to use a setup script that unifies the two htaccess files? It's not uncommon for PHP code to edit/create the .htaccess file when the application is set up or a admin changes settings through PHP.
Was This Post Helpful? 0
  • +
  • -

#3 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5388
  • View blog
  • Posts: 27,384
  • Joined: 10-May 07

Re: Can Apache2 use 2 .htaccess files in the same directory?

Posted 22 March 2012 - 09:08 PM

Using vhosts you could assign each virtual host it's own access file. But one that variable is assigned for a host, you can't assign it a 2nd. Through the shell you could copy access log files with cron tabs though.

Be creative ;)
Was This Post Helpful? 0
  • +
  • -

#4 icedd  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 98
  • Joined: 04-March 08

Re: Can Apache2 use 2 .htaccess files in the same directory?

Posted 14 April 2012 - 03:22 PM

View PostAtli, on 22 March 2012 - 11:17 AM, said:

No, I don't believe there is a way to do that. Like that SO link suggested you can use AccessFileName to specify a list of potential access files but it will only read the first file it finds that matches the list.

The server config file has a Include directive that can include other config files but it's not available to .htaccess files. I assume editing the server config file to include your second .htaccess file is not what you want?


This package you are making. Would it not be possible to use a setup script that unifies the two htaccess files? It's not uncommon for PHP code to edit/create the .htaccess file when the application is set up or a admin changes settings through PHP.


Hrm, perhaps it would be best to just make a bash script to append the information to the existing .htaccess file. (I assume you can do that), I don't have much experience with bash scripting. I've used so backup bash scripts and know just about enough to change file paths and edit date stamp formats. I guess I need to find a bash scripting tutorial.

Thanks.
Icedd
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1