Multiple .htaccess |
[eluser]simshaun[/eluser]
What I'd like to do is implement caching through my htaccess file, but I only want it enabled for a subdirectory of controllers. Normally, I could put a .htaccess file in a subdirectory if I wanted it only to apply for that directory. With CI, I'm a little befuddled about how to mimic this. This is what ought to happen... .htaccess in root contains rules for everything .htaccess in controllers/admin/ contains rules only for files under http://localhost/admin/ I've tried this in the root .htaccess file: <Directory /admin> ExpiresActive on ExpiresDefault "modification plus 30 days" </Directory> But it's throwing me a 500 error. I'm running Apache/PHP through Vista, and mod_expires is enabled in apache. Here's my full .htaccess file (it works without the <Directory>...</Directory> block) Code: # Deny OR Allow Folder Indexes.
[eluser]Colin Williams[/eluser]
Your .htaccess instructions instruct Apache, not CodeIgniter, which you have handling all requests for '/admin' (and your third and fourth RewriteCond appear superfluous). What you would need to do is server the expires headers from CI, which you can do with PHP or via CI's Output class (check the docs). Could be done in the constructor of your Admin controller class
[eluser]simshaun[/eluser]
Yes the repos and user_guide cond arent needed. It's obvious that htaccess doesn't control CI, and I'm not trying to. What I'm trying to do essentially is enable caching for anything under a certain directory in the URI. I assumed it's possible, but I guess not. I already planned on trying to send the cache params through header via a base controller that all the admin controllers extend from. I thought it would have been easier to do it in .htaccess. Thanks though.
[eluser]Colin Williams[/eluser]
Quote:It’s obvious that htaccess doesn’t control CI, and I’m not trying to ... I thought it would have been easier to do it in .htaccess.
[eluser]simshaun[/eluser]
I'm assuming that is supposed to be a jab at me, as if I'm contradicting myself, but I'm not. Care to make a reply that actually contains more info than what I've already stated?
[eluser]Colin Williams[/eluser]
I just thought it needed clarification. And I don't know what more to offer. It's clear that your need to serve the expiration headers from CI. The higher up you serve them (controller, base controller, hook, front controller...) the more broad the application will be.
[eluser]simshaun[/eluser]
Thankyou. Yea the idea is to force caching on (all) files located inside admin.
[eluser]yelirekim[/eluser]
My first question is: do you have an actual directory called /admin/, or is Admin one of your controllers? If this is the case then just disregard what I'm saying below and think a little bit about this: you're trying to apply an apache directive to a folder which doesn't exist on the server. If admin is actually a folder, I don't think you can put a <directory> tag within another <directory> tag, which is essentially what you are doing here. When you put an .htaccess file inside a folder, apache appends a <directory> tag to your directives for the folder that the .htaccess file is inside. This isn't precisely what happens, but it's accurate for illustrative purposes. Anyways, I think what you should probably do is just create another .htaccess file inside the /admin folder... It should work fine.
[eluser]simshaun[/eluser]
/admin is not an actual directory. At first I was attempting <Directory> but then found <LocationMatch>, which is how I would achieve this. The only thing is, both <Directory> and <LocationMatch> are not allowed in .htaccess, so Apache's httpd.conf file needs to modified instead. So, I use a <LocationMatch> tag and I came up with this: (which I'm pretty sure works): Code: <LocationMatch "/admin">
[eluser]yelirekim[/eluser]
I wasn't even aware <LocationMatch> was a valid apache tag, learn something new every day I guess Glad you got it worked out. |
Welcome Guest, Not a member yet? Register Sign In |