Hypertext Access aka htaccess is a file used to configure the apache web server. It is accepted by the server as a component and allows us to dynamically navigate and enable features or protect a certain part (folder) of the site.
Join the channel Telegram of the AnonyViet 👉 Link 👈 |
In the name .htaccess, htaccess is the extension and this file has no name, so when you put this file on the host it is not always displayed. For example, if you use Total Commander to handle FTP files, you will not be able to see the .htaccess file.
To manipulating .htaccess files You can use any text editor like Netbeans, PHP Designer, or even the notepadd software available in windows.
Today I will guide you to Anti DDOS and Secure Hosting with .htaccess
Step 1 : Create 1 file .htaccess on your computer or through Cpanel hosting
Step 2 : Open the .htaccess file with any editor
Step 3 : Add the following content to the .htaccess file
order deny,allow allow from 210.245.90.203 deny from all
According to the above text line, IP 210.245.90.203 will be allowed in your admincp directory, in addition, other IPs will not be accessible except the Allowed IP. To check your computer’s IP, you can refer to this lesson
How to safely chmod files:
Normally when you upload files to hosting the files and folder will default to chmod as
For File to be: 644
for Foder is: 755
and most source code will require chmod file config.php to 777this is very dangerous when a configuration file is chmod 777 because it has full authority, read + write + delete so you shouldn’t chmod any files to 777 but please chmod standard in the following way to be safe
For File : 644 or 600
For files config.php or wp-config.php let’s chmod : 400 To ensure the security of your website
Never chmod these files to 777
If any file needs to access read and write data, then chmod 666 instead of chmod 777
Secure any file with .htaccess
<FILES WP-CONFIG.PHP> ORDER ALLOW,DENY DENY FROM ALL </FILES>
Protect .htaccess files
<FILES .HTACCESS> ORDER ALLOW,DENY DENY FROM ALL </FILES>
Create a simple soft Firewall with .htaccess to fight DDOS
Create a .htaccess file in the directory subject to DDoS access/request continuously (usually the public_html, forum, diendan, 4rum, etc. folders). The file contents are as follows:
RewriteEngine on RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?domaincuaban.com [NC] RewriteRule !antiddos.phtml http://domaincuaban.com/antiddos.phtml?%{REQUEST_URI} [QSA]
Then create file antiddos.phtml placed in the same directory as the .htaccess file, with the content:
<? $text=$HTTP_SERVER_VARS['QUERY_STRING']; $text = preg_replace("#php&#si",'php?',$text); echo('<center><a href=http://domaincuaban.com'.$text.'>[Nhấn và o đây]</a><br>để và o trang chủ.</center>'); ?>
Redirect Website when being DDOS, when DDOS attacks will target your Domain, to protect the database to avoid wasting bandwidth for hosting, you can redirect the Domain to another destination eg: facebook.com
Then the attacks instead of hitting your domain will be forwarded DDOS packets via Facebook.
RewriteEngine On RewriteRule ^(.*)$ http://facebook.com/\ [R=301,L]
Prevent running any of your files through other websites (this can prevent stealing image files as well as other files to avoid wasting your resources)
#CHONG TROM FILE REWRITEENGINE ON REWRITECOND % !^$ REWRITECOND % !^HTTP://(WWW.)?TENMIENCUABAN.COM/.*$ [NC] #REWRITERULE .(GIF|JPG)$ – [F] #REWRITERULE .(GIF|JPG)$ HTTP://WWW.anonyviet.com/FILE.JPG [R,L]
You can add any file name in the . section (gif|jpg)
Prevent running other domains on your website
REWRITEENGINE ON REWRITECOND % DUYQUANG.NET [NC] REWRITERULE .* – [F]
Deduplication of content
# SET THE CANONICAL URL REWRITEENGINE ON REWRITECOND % ^TENMIENCUABAN.COM$ [NC] REWRITERULE ^(.*)$ HTTP://WWW.TENMIENCUABAN.COM/\ [R=301,L]
Anti-Spam comment
REWRITEENGINE ON REWRITECOND % POST REWRITECOND % .WP-COMMENTS-POST.PHP* REWRITECOND % !.*TENMIENCUABAN.COM.* [OR] REWRITECOND % ^$ REWRITERULE (.*) ^HTTP://%/$ [R=301,L]