Monthly Archives: April 2017

How you can block IP addresses through cPanel interface

There are many occasions when you may need to block IPs. Maybe there is a bad bot or just an IP trying to get access to your WordPress admin area. cPanel allow you to easily block IPs.
The steps to block an IP or IP range are:

  1. Log into your cPanel account
  2. Go to SECURITY area -> IP Blocker
  3. Enter the IP (or IP range) that you want to block in the field IP Address or Domain
  4. Click the Add button.  Now, those IPs will not be able to access your site anymore.
Notice that you can also input domain names in this tool(like bad-site.com). The IP Blocker will automatically find the IP of the domain.
cPanel IP Blocker
cPanel IP Blocker

And the video tutorial is here:

What is and how to use the public_ftp folder

The folder /home/username/public_ftp/ is used by the FTP server to store files for the “anonymous” users. Anonymous users are users that connect to the FTP server with the “anonymous” username. They don’t need to have a password.

 

public_ftp folder
public_ftp folder in cPanel File Manager
Notice that you have a similar folder in your account /public_html/ – this folder stores the site’s content that is available for the public. Do not delete this folder.
For security reasons, anonymous FTP is disabled on most of the shared and reseller servers. Ask your host for more details.

How to remove .php, .html extensions with .htaccess

Many times you will want to have user-friendly URLs on your site. Instead of https://www.example.com/index.html you will want to have https://www.example.com/index . The second URL looks much better. Also, from the SEO point of view is better to don’t use file extensions.

 The steps to remove file extensions are:

  1. Login to your cPanel account.
  2. Go to File Manager – in the FILES Section
  3. In the File Manager go to the Settings button on the top right corner.
  4. On the Preferences window that will appear check the Show Hidden Files (dotfiles) option. Click Save button to apply the settings.
  5. Now navigate to the .htaccess file. If the file doesn’t exist you will need to create it.
  6. Click the Edit button from the File Manager top menu.
  7. Add the below lines to the .htaccess file. Click the Save Changes button and then the Close button. 
    #remove php file extension-e.g. https://example.com/file.php will become https://example.com/file
    RewriteEngine on 
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php [NC,L]
    
  8. Now the Apache web server will remove .php extension from URLs.

To remove .html extension use:

#remove html file extension-e.g. https://example.com/file.html will become https://example.com/file
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
Notice that many PHP scripts (like WordPress, Drupal, MediaWiki etc) need the .htaccess files to function properly. Don’t delete these files. Also take care when editing them.

Check the video tutorial we made:

You can also edit .htaccess files on your web hosting account via an FTP client like FileZilla.

How to force www or non-www URLs for your domain via .htaccess in cPanel

To redirect URLs on your site you can use the .htaccess files. We will show you below how to redirect non-www URLs to www URLs and vice versa.
To see more info on how to edit .htaccess files via cPanel please check this Knowledge Article.

htaccess nonwww to www
.htaccess redirect nonwww to www

To force URLs to www version use:

# Redirect non-www URLs to www URLs - like http://yourdomain.com to http://www.yourdomain.com
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com [NC]
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]

To force URLs to non-www version use:

# Redirect www URLs to non-www URLs - like http://www.yourdomain.com to http://yourdomain.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com [NC]
RewriteRule (.*) http://yourdomain.com/$1 [R=301,L]
Notice that many PHP scripts (like WordPress, Drupal, MediaWiki etc) use the .htaccess files to function properly. Don’t delete these files. Also take care when editing them.

How to deny access to a specific file on your site via .htaccess

Do you want to keep a file on your web hosting account private? You can do so by blocking access to it via a rule in the .htaccess file. The steps are:

  1. Login to your cPanel account.
  2. Go to File Manager – in the FILES Section
  3. In the File Manager go to the Settings button on the top right corner.
  4. On the Preferences window that will appear check the Show Hidden Files (dotfiles) option. Click Save button to apply the settings.
  5. Now navigate to the .htaccess file. If the file doesn’t exist you will need to create it.
  6. Click the Edit button from the File Manager top menu.
  7. Add the below lines to the .htaccess file. Click the Save Changes button and then the Close button. 
    #block access to the file blockedfile.html; permit access to all other files
    <files blockedfile.html>
    Order Allow,Deny
    Deny from all
    </files>
    
  8. Now access to the file blockedfile.html will be blocked. Users will see a 403 Forbidden error.

To block access to specific files (like images), use these lines instead:

#block access to image files - files with jpg/gif/png/jpeg extensions
<FilesMatch "\.(jpg|gif|png|jpeg)$">
Order Allow,Deny 
Deny from all 
</FilesMatc>
Notice that many PHP scripts (like WordPress, Drupal, MediaWiki etc) need the .htaccess files to function properly. Don’t delete these files. Also take care when editing them.

Check the video tutorial we made:

You can also edit .htaccess files on your web hosting account via an FTP client like FileZilla.
Page 6 of 7
1 4 5 6 7