PDA

View Full Version : .htaccess scope



Bob Barr
03-06-2011, 08:30 PM
Are lines added to the .htaccess file in the public_html folder applied down into subfolders for addon domains and subdomains? Or do those lines need to be duplicated into separate .htaccess files in those folders?

bobdog
03-07-2011, 10:16 AM
What is it you want .htaccess to do in sub folders? Sometimes I have to put an htaccess in folders for a redirect, or make a DirectoryIndex.

Bob Barr
03-07-2011, 12:19 PM
What is it you want .htaccess to do in sub folders? Sometimes I have to put an htaccess in folders for a redirect, or make a DirectoryIndex.
I'd like to add cache expiration controls for all of my sites and was wondering if doing it once in public_html would be sufficient or if I'd have to add them in the subfolders as well.

SteveS
03-07-2011, 02:21 PM
I'd like to add cache expiration controls for all of my sites and was wondering if doing it once in public_html would be sufficient or if I'd have to add them in the subfolders as well.

Once in the public_html folder is all that is required. I recently did the same thing for all of my sites. If you want to check the headers returned from the server, you may use http://redbot.org/? or the developer tools or add-ons for your browser.

You can also override the settings for a specific sub-folder if you want.

Bob Barr
03-07-2011, 02:49 PM
Thanks for the information and the link. (I hadn't looked into such tools for Firefox, my usual browser. I wouldn't be surprised if they exist as browser plugins.)

SteveS
03-07-2011, 02:52 PM
This is what I use for Firefox

http://livehttpheaders.mozdev.org/

dpbklyn
03-31-2011, 09:49 AM
@Bob

Hello and thank you in advance!

I am trying to create an .htaccess file to force visitor's browsers to refresh. For some reason, my meta tags stopped working recently. I am horribly confused as to what i have to put into the .htaccess file in order to force a refresh. ANy help would be greatly appreciated!

Thank you,

dp

SteveS
03-31-2011, 11:07 AM
I am trying to create an .htaccess file to force visitor's browsers to refresh. For some reason, my meta tags stopped working recently. I am horribly confused as to what i have to put into the .htaccess file in order to force a refresh. ANy help would be greatly appreciated!

Thank you,

dp

Follows is an example of what can be used in your .htaccess file. You will of course need to customize to fit your needs.


### activate mod_expires
ExpiresActive On
### Expire everything 1 day from when it's last accessed
ExpiresDefault "access plus 1 day"
### Expire php files immediately
<FilesMatch "\.(php)$">
ExpiresDefault A0"
</FilesMatch>
### Apply a Cache-Control header
Header append Cache-Control "must-revalidate"


Unfortunately, if a specific user's browser already has everything cached for an extended period of time, then the browser will not even make a request to the server for the page (unless the user forces a refresh). It will just use the cached version of the page. After the browser again retrieves the page from the server, then the new .htaccess parameters for caching will be in effect.

dpbklyn
03-31-2011, 11:45 AM
Thank you for the quick reply...

Will this also expire and refresh HTML files?

Thank you,

dp

SteveS
03-31-2011, 11:55 AM
Will this also expire and refresh HTML files?

In the example I provided, every type of file (html, htm, gif, jpg and etc.) except php will expire 1 day after the last access. Php files will expire immediately. Most likely the parameters in the example will not be appropriate for your site. Typically gif files and jpg files will benefit from a longer expiration time unless they are frequently changed.

dpbklyn
03-31-2011, 11:57 AM
yep...I saw that after I hit send...

I appreciate your replay, thank you!