Automatically set permission to various file types using .htaccess

Set file permissions with .htaccess, this is a great method for ensuring the CHMOD settings for various file types.

 

Apply the following rules in the root .htaccess file to affect all specified file types, or place in a specific directory to affect only those files (add/update file types according to your needs)

[sourcecode language=”plain”]
# ensure CHMOD settings for specified file types
# never set CHMOD 777 unless you know what you are doing?
# files requiring write access should use CHMOD 766 rather than 777
# keep specific file types private by setting their CHMOD to 400

chmod .htpasswd files 640
chmod .htaccess files 644
chmod php files 600
[/sourcecode]

 

Require SSL (Secure Sockets Layer)

Here is an easy way you can go using .htaccess file

[sourcecode language=”plain”]
# require SSL without mod_ssl
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
[/sourcecode]

 

Guys, If you still face any issue regarding this, leave a comment in the comment box.

 

One thought on “Automatically set permission to various file types using .htaccess”

Comments are closed.