Restrict .htacess rules to only one folder

0

I need to optimize a page that is inside a / site folder and would like to enable cookies, but they can not be enabled for the other folders.

How can I make a condition or rule that limits only this folder?

Code

ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 604800 seconds"
ExpiresByType application/javascript "access plus 604800 seconds"
ExpiresByType text/html "access plus 2592000 seconds"
    
asked by anonymous 17.03.2017 / 18:37

2 answers

0

I'll leave the solution here as it may be useful to other users.

After much research I discovered that it is necessary to create an httpd.conf file with the directory tag to limit the rules only to the desired folder ...

link

<Directory /site>
  <IfModule mod_expires.c>
    # Cookies
    ExpiresActive On
    ExpiresDefault "access plus 1 seconds"
    ExpiresByType image/jpeg "access plus 2592000 seconds"
    ExpiresByType image/png "access plus 2592000 seconds"
    ExpiresByType image/gif "access plus 2592000 seconds"
    ExpiresByType text/css "access plus 604800 seconds"
    ExpiresByType text/javascript "access plus 604800 seconds"
    ExpiresByType application/javascript "access plus 604800 seconds"
    ExpiresByType text/html "access plus 2592000 seconds"
  </IfModule>
</Directory>

Apache Link

    
17.03.2017 / 20:11
0

If I did not have administrative permission to the server, what happens a lot on shared servers just play .htaccess on the desired folder:

public_html
├───index.php
├───.htaccess
├───images
|   ├───.htaccess
|   └───1.jpg
├───css
|   ├───.htaccess
|   └───main.css
└───js
    ├───.htaccess
    └───main.js

Each folder with its own .htaccess

Note ExpiresDefault has nothing to do with cookies, this does not activate cookies, it only defines the cache of images for the client, cookies are data that writes to the client and can be reused and not cache.

I think this should help:

17.03.2017 / 21:03