Advance

Htaccess Tricks on Cpanel Linux Host

Htaccess Tricks on Cpanel Linux Host

Htaccess Tricks on Cpanel Linux Host;

Some Linux users may not be aware of “htaccess” powers.

You need to know that some of these tricks are necessary to protect your web server from hacker attacks. Others will be able to perform simple and effective tasks such as redirecting web server and website optimization. The following htaccess will be able to help you easily redirect and optimize the webserver.

15 Htaccess Tips and Tricks on cPanel Linux Host

1 – Set time zone:

Sometimes when you use the date or mktime function in PHP, it will show you a funny time zone message. It’s easy to solve this problem. Set the time zone on your server. The timezone support list can be found here.

SetEnv TZ Australia/Melbourne

2 – SEO Content and 301 Permanent Change Paths:

Today, some modern search engines are able to detect 301 permanent redirects and update existing records.

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

3 – Exclude 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 code in the htaccess file.

AddType application/octet-stream .pdf AddType application/octet-stream .zip AddType application/octet-stream .mov
Recommended Article: Database correction with database management tools with MySQL

 

4 – Remove the WWW

One of the SEO guidelines is to make sure that only one URL points to your website. So you’ll need to redirect all WWW traffic to a non-WWW route.

Use the following codes to do this:

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

5 – Customize Error Page:

Create a custom error page for each error code.

ErrorDocument 401 /error/401.php ErrorDocument 403 /error/403.php ErrorDocument 404 /error/404.p

ErrorDocument 500 /error/500.php

6 – Compress files:

Optimizing the time to load a website can be done by compressing files to smaller sizes.

# compress text, html, javascript, css, xml: AddOutputFilterByType DEFLATE text/plain

a) AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml

b) AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE application/xml

c) AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE

application/rss+xml AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType

DEFLATE application/x-javascript

7 – Cache files:

File saving is popular way of optimizing a website when loading.

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

8 – Disable 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

Htaccess Tricks on Cpanel Linux Host;

Security

Subsequent htaccess codes will be able to improve the security level of your web server. Hotlinking protection is very useful in preventing the use of images stored on a web server.

1 – Hotlinking protection with htaccess

By using the below code you can prevent the bandwidth of your website being stolen by using the images you hosted on your web server.

RewriteBase / RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www.)

joomir.com/.*$ [NC] RewriteRule .(gif|jpg|swf|flv|png)$ /feed/ [R=302,L]

2 – Prevent hacking your website

To improve the security level of your website, use the following codes. These codes will prevent some hacking techniques by detecting malicious URLs.

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]

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 order allow,deny deny from all # prevent viewing of a specific file order

allow,deny deny from all # multiple file types <FilesMatch “.

(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$”> Order Allow,Deny Deny from all

4 – Rename the htaccess file

You can rename the htaccess file to something else to prevent others from accessing it.

AccessFileName htacc.ess

5 – Change the default index page

You can change the default index.html page or index.php or index.htm to something else.

DirectoryIndex business.html
Recommended Article: How to fix Internal Server Error 500

 

6 – Block unwanted visitors by domain hint

# block visitors referred from indicated domains RewriteEngine on RewriteCond %{HTTP_REFERER}

scumbag.com [NC,OR] RewriteCond %{HTTP_REFERER} wormhole.com [NC,OR] RewriteRule .* – [F]

7 – Secure directories by disabling execution scripts

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

Htaccess Tricks on Cpanel Linux Host;

Goodluck.

We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

Leave a Reply

Your email address will not be published. Required fields are marked *

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way

+8595670151

7 days a week, 24 hours a day