Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
htaccess in subdirectory
  • Anyone know how to add an .htaccess file in a subdirectory? For example, I have the following directory structure for controllers: app/classes/controller/public
    app/classes/controller/admin I would like to have an .htaccess file only for the admin folder (possibly to set htpasswd or change the caching). I've added the .htaccess file, but it doesn't seem to be used.
  • What would you need this for? The controllers are called from the index.php, and should be hidden below your public directory (meaning they would be hidden). Then they would be executable whenever they are called. If you want your admin controller to be password protected, you should handle this from your controller. If you like the little password popup box that Apache uses with .htpasswd, look into this: http://php.net/manual/en/features.http-auth.php You'll most likely want to look into AUTH_DIGEST.
  • My examples were not very good. I do have a full-blown auth for my administration sections, although sometimes during development I need a quick protection of some folders. I guess because Fuel runs everything through index.php there's only one htaccess file. One thing in particular I was experimenting with is set up of caching in the htaccess file. I have several lines of code dealing with expiration for different types of files such as:
    ExpiresByType text/html A0. This line stops caching of all the web files generated by Fuel since they appear as Content-type "text/html". This is needed in administration sections, since many of the pages are dynamic and change the database. If caching were enabled, the pages show out of date data. However, this also turns off caching for public web pages that are not dynamic or at least don't need to change every time the page is displayed. I was wondering if there was a way to enable caching for public files and turn off caching for admin files, so my first thought was to add another htaccess file just for the admin folder.
  • Have you looked into html5boilerplate? Just using them as an example, by default they utilize:
    ExpiresByType text/html                 "access plus 0 seconds"
    

    Generally speaking, when caching comes into the picture, you want people to be caching things such as stylesheets, javascripts, and images (generally referred to as your sites assets) rather than the content themselves (the html output), as these are the assets that are utilized on all of your pages. Even if, for example, you're on an "About Us" page which will generally not change as often as say, a news page, you would want to retain the same caching, because if you ever change that content, you want it to be updated automatically. I would look into the boilerplate, as it has a lot of good examples for this. If you decide not to go that route, I can help you do some research. But that's how we've done it for every company I've worked for, which are multi-million dollar companies.
  • It's interesting that you mention html5boilerplate, because I was looking through their website and code just last week. Like most developers, I have default settings for my htaccess files that I've developed over time, but I guess playing with Fuel has made me go back and take another look at some of the things I typically do. My htaccess file has essentially the same ExpiresByType line that you referenced. I have on my "to do" list to go back and take a detailed look at html5boilerplate. Regarding not caching pages like "About Us," maybe you're right and it's not worth the effort to try to enable caching for them. On the other hand, even a page like News which would be likely to change more often, would update after the cache expires time. So you could cache it for say 24 hours. Out of curiosity, I do wonder if there's a way to cache public pages and not cache admin pages.
  • As far as the fuel core is concerned, nothing is provided (to my knowledge) to allow you to do this. That being said, there's probably some workarounds you could do within your apache configurations to change up the cache based on URI, but I honestly don't think this is something that's practical. This whole concept just seems very strange to want to do, but definitely let me know if you find anything.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion