DED9

Some Htaccess tips and tricks in cPanel Linux hosting

Some Linux host users may not be aware of the power of htaccess. Some of these tricks are necessary to protect your web server from hacker attacks, and others will be able to do simple and effective things such as changing the path of web server and website optimization. Was. Linux cPanel

 

The following htaccesses will be able to help to redirect and optimize the web server easily.

[thumbnail target=”_self” alt=”Some Htaccess tips and tricks in cPanel Linux hosting” src=”https://www.shopingserver.net/wp-content/uploads/2018/04/Network-Security-min- 1200×565.jpg”]

1- Setting the time zone:

Sometimes when you use tarij or the mktime function in PHP it will show you a funny message about the time zone. It is easy to solve this problem, set the time zone on your server. A list of time zone support can be found here.

SetEnv TZ Australia/Melbourne

2- The content of SEO and 301 path of permanent change:

Today, some modern search engines have the ability to detect 301 permanent path changes and update existing records.

Redirect 301 http://www.test.com/home http://www.test.com/

3- To dismiss the download dialog:

Usually when you try to download something from a web server you get a request to save or open the file. To avoid this request, enter the following codes in the htaccess file.

1.AddType application/octet-stream .pdf
2.AddType application/octet-stream .zip
3.AddType application/octet-stream .mov

[thumbnail target=”_self” alt=”Some Htaccess tips and tricks in cPanel Linux hosting” src=”https://www.shopingserver.net/wp-content/uploads/2018/04/images-25.jpg” ]

4- Delete WWW

One SEO recipe is to make sure that only one URL points to your website, so you will need to redirect all WWW traffic to a non-WWW path. Use the following caches for this. Linux cPanel

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.joomir.com [NC]
RewriteRule ^(.*)$ http://joomir.com/$1 [L,R=301]

5- Customizing the error page:

Create a custom error page for each error code

1.ErrorDocument 401 /error/401.php
2.ErrorDocument 403 /error/403.php
3.ErrorDocument 404 /error/404.p 
4.ErrorDocument 500 /error/500.php

 

6- Compression of files:

You can optimize website loading time by compressing files to smaller sizes.

# compress text, html, javascript, css, xml:
1.AddOutputFilterByType DEFLATE text/plain
2.AddOutputFilterByType DEFLATE text/html
3.AddOutputFilterByType DEFLATE text/xml
4.AddOutputFilterByType DEFLATE text/css
5.AddOutputFilterByType DEFLATE application/xml
6.AddOutputFilterByType DEFLATE application/xhtml+xml
7.AddOutputFilterByType DEFLATE application/rss+xml
8.AddOutputFilterByType DEFLATE application/javascript
9.AddOutputFilterByType DEFLATE application/x-javascript

7- Storage files (Cache files):

Saving a file is another popular method when optimizing a website while it is loading.

<FilesMatch “.(flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf)$”> Header set Cache
-Control “max-age=2592000”
</FilesMatch>

 

8- Disabling storage for certain types of files:

You can disable storage for certain types of files.

# explicitly disable caching for scripts and other dynamic files
<FilesMatch “.(pl|php|cgi|spl|scgi|fcgi)$”>
Header unset Cache-Control
</FilesMatch>

 

 

[thumbnail target=”_self” alt=”Some Htaccess tips and tricks in cPanel Linux hosting” src=”https://www.shopingserver.net/wp-content/uploads/2018/04/bec1c14fce73ac993608dc169eee8174.jpg”]

 

security

The following htaccess codes will be able to increase the security level of your web server . Hotlinking protection is very useful to prevent the use of images stored on the web server. Linux cPanel

 

1- Protecting Hotlinking with htaccess
Do you hate having your website bandwidth stolen by using images you host on your web server? You can avoid this by using the code below. Linux cPanel

RewriteBase /
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?joomir.com/.*$ [NC]
RewriteRule .(gif|jpg|swf|flv|png)$ /feed/ [R=302,L]

 

2- Prevent your website from being hacked

If you want to increase the security level of your website, use the following codes. These codes will prevent some hacking techniques by discovering malicious URLs. Linux cPanel

RewriteEngine On
# proc/self/environ? no way! 
RewriteCond %{QUERY_STRING} proc/self/environ [OR]
# Block out any script trying to set a mosConfig value through the URL 
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\% 3D) [OR]

# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]

# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]

# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|[|\%[0-9A-Z]{0,2}) [OR]

# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|[|\%[0-9A-Z]{0,2})

# Send all blocked requests to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]

 

3- Block access to your htaccess file

The following code will prevent the user from accessing the htaccess file. You can also block multiple files.

# secure htaccess file
<Files .htaccess>
order allow, deny
deny from all
</Files>

# prevent viewing of a specific file
<Files secretfile.jpg>
order allow, deny
deny from all
</Files>

# multiple file types
<FilesMatch “.(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$”> Order
Allow, Deny
Deny from all
</FilesMatch>

4- Changing the name of the htaccess file
You can change the name of the htaccess file to something else to prevent others from accessing it.

AccessFileName htacc.ess

5- Disable directory browsing
Prevent the server from displaying the directory index. Linux cPanel

# disable directory browsing
Options All -Indexes
# enable directory browsing
Options All +Indexes

6- Changing the default index page
You can change the default index.html or index.php or index.htm page to something else. Linux cPanel

DirectoryIndex business.html

7- Blocking unwanted visitors based on domain reference

# block visitors referred from indicated domains
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_REFERER} scumbag.com [NC,OR]
RewriteCond %{HTTP_REFERER} wormhole.com [NC,OR]
RewriteRule .* – [F]
</ ifModule>

8- Blocking the request based on the User-Agent header.
This method can increase your bandwidth quota by blocking certain bots or prevent spider hacking from entering your website.

# block visitors referred from indicated domains
<IfModule mod_rewrite.c>
SetEnvIfNoCase ^User-Agent$ .*(craftbot|download|extract|stripper|sucker|ninja|clshttp|webspider|leacher|collector|grabber|webpictures) HTTP_SAFE_BADBOT SetEnvIfNoCase ^
User -Agent$ .*(libwww-perl|aesop_com_spiderman) HTTP_SAFE_BADBOT
Deny from env=HTTP_SAFE_BADBOT
</ifModule>

[thumbnail target=”_self” alt=”Some Htaccess tips and tricks in cPanel Linux hosting” src=”https://www.shopingserver.net/wp-content/uploads/2018/04/computer-security-990× 658.jpg”]
9- Securing directories by disabling script execution

# secure directory by disabling script execution
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
Options -Ex

Exit mobile version