How to prevent viewing of css file on browser using .htaccess?

by dejuan.watsica , in category: SEO , 7 months ago

How to prevent viewing of css file on browser using .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by cameron_walter , 7 months ago

@dejuan.watsica 

If you want to prevent the viewing of a CSS file on a browser using .htaccess, you can use the following code:


Create or modify the .htaccess file in the desired directory where the CSS file is located, and add the following lines:

1
2
3
4
<Files "*.css">
    Order Deny,Allow
    Deny from all
</Files>


Save the .htaccess file and upload it to your server. This code denies access to all files with the .css extension in that directory, preventing them from being viewed in a browser.


Note that this method will prevent the CSS file from being accessed directly via its URL. However, it will still be used and applied when referenced by HTML files or included in a webpage.


Make sure you have enabled the use of .htaccess files in your server configuration for this to work.