There is a main.css file, which is available through a direct link http://test4.dev.3klika.ru/main.css

The .htacccess contains the lines:

 RewriteEngine on RewriteRule \.(css|)$ - [NC,F,L] 

but the file is available both when connected in <head> , and by direct link.


I need to redirect all requests for .css files to a .php file that will compress the styles and save the file to the cache, so the option "delete file" is not suitable.


Redroid, thanks for the reply.

The problem is that having an entry in .htaccess:

 RewriteRule ^css/(.*).css$ /t.php [L] 

And when I click on the link http://test4.dev.3klika.ru/css/main.css , I get exactly the .css file, not the .php. (The .php file is, is available, contains a banal print ());

  • Why ban access to styles? Delete the files then. - user207618
  • From the server’s point of view, there is no difference between the link in head (link) and the direct link. - Alexey Ten
  • Strange service where I can not leave comments due to lack of rating. I need to redirect all requests for .css files to a .php file that will compress the styles and save the file to the cache, so the option "delete file" is not suitable. - brzlvch
  • @Viktor Barzilovich It seems that you asked a question from one account, but you supplement it with another - that’s why you cannot comment on your own question. I will send a request to merge uchetku. Comments anywhere can be left after a set of 50 reputation, it is quite quickly done and needed to protect the site from spam. - Nick Volynkin
  • You have 500 errors everywhere, maybe in .htaccess mb you are trying to use apache modules that are not installed? - Redr01d

2 answers 2

Regarding compression on the fly, I do this, put in the code real links to real files that physically lie there where indicated in the code, in .htaccess I prescribe an overload to the PHP script with the file name parameter, the script checks the last change date script and if nothing has changed gives the cache, otherwise minifitsiruet file puts in the cache and gives compressed:

 #генератор manifest RewriteRule (cache.manifest)$ /common/tool/manifest_gen.php [L] #минификация js-css #RewriteRule ^common/(.*).js$ /common/tool/static.php/?filename=$1.js [L] #RewriteRule ^common/(.*).css$ /common/tool/static.php/?filename=$1.css [L] 

Thus, even if the script is accessed directly, always get a compressed version.

    in the folder with the files that should be prohibited, you should place the file .htaccess

     <FilesMatch ~ "\.(css|html)$"> Order allow,deny Deny from all </FilesMatch> 

    but in general, use Google answer from here