Some Htaccess tips and tricks in cPanel Linux hosting
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 [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 5- Customizing the error page: Create a custom error page for each error code 1.ErrorDocument 401 /error/401.php
You can optimize website loading time by compressing files to smaller sizes. # compress text, html, javascript, css, xml: 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
You can disable storage for certain types of files. # explicitly disable caching for scripts and other dynamic files
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
RewriteBase /
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 # Block out any script trying to base64_encode crap to send via URL # Block out any script that includes a <script> tag in URL # Block out any script trying to set a PHP GLOBALS variable via URL # Block out any script trying to modify a _REQUEST variable via URL # Send all blocked requests to homepage with 403 Forbidden error!
The following code will prevent the user from accessing the htaccess file. You can also block multiple files. # secure htaccess file # prevent viewing of a specific file # multiple file types 4- Changing the name of the htaccess file AccessFileName htacc.ess 5- Disable directory browsing # disable directory browsing 6- Changing the default index page DirectoryIndex business.html 7- Blocking unwanted visitors based on domain reference # block visitors referred from indicated domains 8- Blocking the request based on the User-Agent header. # block visitors referred from indicated domains
2.AddType application/octet-stream .zip
3.AddType application/octet-stream .mov
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.joomir.com [NC]
RewriteRule ^(.*)$ http://joomir.com/$1 [L,R=301]
2.ErrorDocument 403 /error/403.php
3.ErrorDocument 404 /error/404.p
4.ErrorDocument 500 /error/500.php6- Compression of files:
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
-Control “max-age=2592000”
</FilesMatch>8- Disabling storage for certain types of 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
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
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
# 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]
RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|[|\%[0-9A-Z]{0,2})
RewriteRule ^(.*)$ index.php [F,L]3- Block access to your htaccess file
<Files .htaccess>
order allow, deny
deny from all
</Files>
<Files secretfile.jpg>
order allow, deny
deny from all
</Files>
<FilesMatch “.(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$”> Order
Allow, Deny
Deny from all
</FilesMatch>
You can change the name of the htaccess file to something else to prevent others from accessing it.
Prevent the server from displaying the directory index. Linux cPanel
Options All -Indexes
# enable directory browsing
Options All +Indexes
You can change the default index.html or index.php or index.htm page to something else. Linux cPanel
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_REFERER} scumbag.com [NC,OR]
RewriteCond %{HTTP_REFERER} wormhole.com [NC,OR]
RewriteRule .* – [F]
</ ifModule>
This method can increase your bandwidth quota by blocking certain bots or prevent spider hacking from entering your website.
<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>
# secure directory by disabling script execution
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
Options -Ex