{"id":46,"date":"2020-08-17T08:15:54","date_gmt":"2020-08-17T08:15:54","guid":{"rendered":"http:\/\/blitzfiles.com\/?page_id=46"},"modified":"2024-03-01T10:37:01","modified_gmt":"2024-03-01T10:37:01","slug":"what-can-i-do-with-an-htaccess-file","status":"publish","type":"page","link":"https:\/\/www.blitzfiles.com\/what-can-i-do-with-an-htaccess-file\/","title":{"rendered":"What Can I Do With an .htaccess File?"},"content":{"rendered":"
A lot of Cloudways Platform users have no idea what to do with an .htaccess file. Worry not, because below, we are going to show you many things such as adding suggestions for new server settings, as well as controlling items is 3 different categories.
\nThe good news for you is that you are able to control quite a number of server settings. You will be able to do it through the Server Settings section. You will easily find this in the Server Management area. We urge you to leave us comments, or any questions or suggestions that you might have so that we will look into them.
\nFor all those tasks or settings that cannot be accomplished via the Cloudways Platform, we urge you to use .htaccess files.<\/p>\n
An SSH session is the best way to create or edit a .htaccess file. The first thing that you will have to do is enter your credentials of the application that you want to create or edit when you have opened a session to your server.<\/p>\n
Below, we will list all the actions that you will be able to achieve through the .htaccess file in order to control access to your site, or protect it. The best time to do this is while you are still developing your site or before it becomes public. You will also need to do this if your application is only to be accessed by a limited number of users. This ensures total control.
\n1) Password Protect Your Application
\na) First, make sure that you find the path of the public_html folder of your application. You achieve this by running pwd from the shell.
\n[wjdjmhbxbg]:public_html$ pwd
\n\/home\/08518-6164.cloudwaysapps.com\/wjdjmhbxbg\/public_html
\n[wjdjmhbxbg]:public_html$
\n[wjdjmhbxbg]:public_html$ pwd
\n\/home\/08518-6164.cloudwaysapps.com\/wjdjmhbxbg\/public_html
\n[wjdjmhbxbg]:public_html$
\nb) Next, you will have to add the following code in the .htaccess file:
\nAuthName “Add your login message here.”
\nAuthType Basic
\nAuthUserFile \/home\/08518-6164.cloudwaysapps.com\/wjdjmhbxbg\/public_html\/.htpasswd
\nrequire user name-of-user
\nAuthName “Add your login message here.”
\nAuthType Basic
\nAuthUserFile \/home\/08518-6164.cloudwaysapps.com\/wjdjmhbxbg\/public_html\/.htpasswd
\nrequire user name-of-user
\nc) Now, it’s important that you create the password file .htpasswd, as well as adding a user using the code below. At this point, you want to ensure that you are in the public_html folder of the application that you wish to password protect.
\n[wjdjmhbxbg]:public_html$ htpasswd -c .htpasswd name-of-user
\nNew password:
\nRe-type new password:
\nAdding password for user name-of-user
\n[wjdjmhbxbg]:public_html$
\n[wjdjmhbxbg]:public_html$ htpasswd -c .htpasswd name-of-user
\nNew password:
\nRe-type new password:
\nAdding password for user name-of-user
\n[wjdjmhbxbg]:public_html$
\nThis means that you will be required to provide login details (which you have set above). In order to open access again, you must revert the changes.
\n2) Block Access to Certain IP(s)
\nIf you have been attacked before and happen to know the IP address that attacked you, you will need to take this step. You can add the following code in the .htaccess file of your application:
\norder allow,deny
\ndeny from 46.228.47.114
\ndeny from 46.225.88.5
\nallow from all
\norder allow,deny
\ndeny from 46.228.47.114
\ndeny from 46.225.88.5
\nallow from all
\n3) Block All IP(s) With Few Exceptions
\nYou can allow access to certain IP addresses. We suggest you do this during development:
\norder deny,allow
\ndeny from all
\n# Just Allow a Single IP
\nallow from 84.89.61.164
\norder deny,allow
\ndeny from all
\n# Just Allow a Single IP
\nallow from 84.89.61.164<\/p>\n