Parent and Child .htaccess Relationship

I’m going crazy over here. I have recently moved to make the CMS that was initially integrated into my root mvc framework, to be portable. To make that happen, I just created an mvc framework for the cms and gave it it’s own .htaccess file. Things have been working fine on my local machine, but when I moved the system to a server, all hell broke loose. So, the site root’s .htaccess:


# necessary so that a user can't see a directory index when visiting an actual directory
Options -Indexes

# make forbidden areas look as if they are actually not there
ErrorDocument 403 /incs/404.html.inc

# turn on the rewrite engine (duh)
RewriteEngine on

RewriteBase /       #i don't even think this is necessary
RewriteCond %{REQUEST_URI} !cms
RewriteCond %{REQUEST_URI} !resources   #contains all images, css, etc. all subdirectories should be available
RewriteCond %{QUERY_STRING} !rt=

RewriteRule ^((?>[-\\w]+/?)*)$ index.php?rt=$1&%{QUERY_STRING} [L,R]   #R flag is just for testing

Now, the .htaccess file in the root of the CMS directory, which is very similar:


# necessary so that a user can't see a directory index when visiting an actual directory
Options -Indexes

# make forbidden areas look as if they are actually not there
ErrorDocument 403 /cms/incs/404.html.inc

# turn on the rewrite engine (duh)
RewriteEngine on

RewriteBase /cms
RewriteCond %{REQUEST_URI} !(resources)    #cms has it's own resources directory, same access level
RewriteCond %{QUERY_STRING} !rt=
RewriteRule ^((?>[-\\w]+/?)*)$ index.php?rt=$1&%{QUERY_STRING} [L]

I originally had the index.php file as cmsindex.php (with the appropriate references in the .htaccess file) but looking at the log file showed that the Options directive was being enforced because I had no index.php file at the root. So I renamed it, tried refreshing, and it worked. I was happy! So I went back to the file and removed the R flags for testing and removed some comments and refreshed again, and it was back to being broken! I put back everything I had changed but it was still broken! The error log no longer shows the Options reference, and nothing new has replaced it. I am so lost right now! When I refresh the browser, this url shows up:

http://thedomain.com/cms/?rt=cms

I know the site root’s .htaccess must be getting run, but I don’t see why it would rewrite since I have the !cms RewriteCond in there. I’m in some serious need of guidance! Please!

Sounds like your browser is caching the redirects. Try emptying the cache of your browser, or restart the browser, or even try a full restart of your system if the first two options don’t help (or try in another browser if you have one).

If you’re on firefox, you can install the web developer toolbar which has an option to disable cache. When cache is disabled it also doesn’t cache redirects anymore, very handy! (haven’t found a similar option in google chrome sadly).

Ha! That worked! I can’t believe I didn’t try that on my own! While I’m on the subject, maybe I can pick your brain for an opinion (how often do I have the Programming Guru of the Year’s attention?).

Firstly, do you see any potential problems with the way I have it set up here? I considered using a single .htaccess file in the site root and disabling the one in the CMS for sites that I create and then re-enabling the .htaccess in the cms root if I deploy it to other partners’ clients. I just need to be sure that dropping it into another site (that allows .htaccess modification to server directives of course) is going to work with a minimum amount of tweaks due to conflicts that may arise.

And thank you for your reply! :slight_smile:

Yes what you’re doing there seems sensible to me. I am a big fan of separation: every application should keep as much as it knows to itself and share at least as possible with other applications in terms of code, assets, etc (preferably nothing at all), for the reasons you’ve outlined (easy deployment and management).
Which is of course exactly what you’ve done here :slight_smile:

Awesome, great to hear! Thanks for your time and thoughts!