Restrict . htacess rules to a single folder

Asked

Viewed 57 times

0

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

How can I make a condition or rule that limits only to that 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"

2 answers

0

I will leave the solution here as it may be useful for other users.

After many searches I found that it is necessary to create an httpd.conf file with the tag directory to limit rules only to the desired folder...

httpd.conf

<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>

Link Apache

0

If I didn’t have administrative permission to the server, which happens a lot on servers Shared just play the .htaccess in 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

Observing ExpiresDefault has nothing to do with cookies, this does not activate cookies, it only sets the cache of the images for the client, cookies are data that record in the client and can be reused and not cached.

I think this should help:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.