Tag Archives: .htaccess

How to Configure URL Redirection in cPanel

In this article, we will show you how to setup redirection for your domain in cPanel.

Redirection allows the web server to redirect visitors from one web page to another web page. Its mainly useful on redirecting visitors from an old web page to a new, updated web page and to create shorter URLs that redirect to longer or complex URLs.

Adding a Redirect.

1 Login into your cPanel.

2. Navigate to the Domains sections and Click Redirects.

Domains Section in cPanel.

3. Under Add Redirect, choose the type of redirection from the drop down window:

  • Permanent (301) – This redirect is permanent, it redirects your site to the new website and updates the bookmarks of the visitors.  301 redirect will also direct search engines to the new website.
  • Temporary (302) – The 302 redirects the visitors to the new website, but wont update the visitors bookmarks. Search engines will still index the original site.

Specify the Redirection Type.

4. Choose the domain name you would like to redirect from the drop down window.

Selecting the Domain.

5. In the Redirects to text field, enter the URL of the page/domain to which the domain needs to be redirected.

Specifying the Destination.

6. Select Redirect with or without www to enable www. redirection for your domain.

  • Only redirect with www. − This redirect will only work if the user has entered www. in URL.
  • Redirect with or without www. − This redirect will always be done, regardless of using www. as a part of the URL or not.
  • Do not redirect www. − This redirect will not work if the user has entered www. in URL.

Enabling www. Redirection

6.  Check Wild Card Redirect to redirect all files in the current directory to the same files names in the new directory.

Adding WIldcards.

7. Click on Add to save the settings.

Conclusion

Done! The redirect for the domain has been successfully added. If you need any additional help, feel free to open a ticket with our support team. We’ll be happy to take look. 

 

 

How to Disable Directory Listing Using .htaccess

In this article, we’ll describe how to disable directory listing using .htaccess file.

Directory listing allows all your website visitors to get a complete listing of all the important files and folders in your site simply by typing “http://example.com/yourdir” in the browser. This is very dangerous as it gives outsiders access to the core files in your site. We can be easily prevent this by creating a custom .htaccess file in the root directory of your site.

Quick Steps

  1. Go to your cPanel account open File Manger. 
  2. Click on Settings, check the box “Show hidden files” and click Save.
  3. Open the .htaccess file and add the code “Options All –Indexes”.
  4. Click on “Save Changes” to save and close the file.

Login into your cPanel account and select File Manager from the Files section.

cPanel landing page.

Locate the .htaccess file in the File Manager. The .htaccess file should be located in your public_html directory. If you cant find it, then check if Show Hidden Files is enabled in your File Manager settings:

Creating a new .htaccess file.

If you still can’t find it, then create a new .htaccess file by clicking the File section on the top left corner of your File Manager:Select your .htaccess file and click on the Edit option from the dashboard.

Editing the .htaccess file.

Add the code “Options All –Indexes” and click Save Changes.

Editing the .htaccess file.

Conclusion

The directing listing on your site has been successfully disabled. 

How to Fine-Tune PHP Error Reporting: Complete Disabling and Selective Controls Explained

This article explains how to turn off PHP error messages completely or tweak them to suit your needs.

PHP errors are generated by your websites and logged in error_log files in the directory where your PHP files are located. If you do not need the error_log file you can disable PHP error logging.

To turn off PHP error reporting, you need to add the following line to your .htaccess file to suppress any PHP error messages.

php_flag display_errors off

Quick Steps:

  1. Go to your cPanel account and select File Manager.
  2. Click on Settings, check the box Show hidden files and click Save.
  3. Open the .htaccess file and add the code “php_flag display_errors off”.
  4. Click on Save Changes to save and close the file.

Login into your cPanel account and open File Manager from the Files section.

cPanel home page.

cPanel home page.

Click on Settings in File Manager.

Settings in File Manager.

Settings in File Manager.

Tick the check box “Show hidden files” and click Save.

Settings in File Manager

Select your .htaccess file and click on the Edit option from the dashboard above.

Editing the .htaccess file.

Add the code “php_flag display_errors off” and click Save Changes.

Advanced options

Suppose you don’t want to disable PHP error reporting completely but to log only some specific types of PHP errors. In that case, you can add the following values in the .htaccess file alongside the value “php_flag display_errors on”

To report all types of errors and warnings: E_ALL

php_flag display_errors on
php_value error_reporting E_ALL

It’s the highest level, including notices, warnings, errors, strict standards, and deprecated functions.

To report only fatal errors: E_ERROR

php_flag display_errors on
php_value error_reporting E_ERROR

It does not include warnings, notices, or other non-fatal errors.

To report only warnings: E_WARNING

php_flag display_errors on
php_value error_reporting E_WARNING

It reports only warnings about potential issues that might cause problems but do not stop script execution.

To report only notices: E_NOTICE

php_flag display_errors on
php_value error_reporting E_NOTICE

Reports notice about non-critical issues, such as variable initialization, etc.

To report parse errors only: E_PARSE

php_flag display_errors on
php_value error_reporting E_PARSE

Reports parse errors that occur during PHP script compilation.

To report usage of deprecated functions only:

php_flag display_errors on
php_value error_reporting E_DEPRECATED

Reports usage of deprecated functions or features that might be removed in future PHP versions.

To report coding standards recommendations only:

php_flag display_errors on
php_value error_reporting E_STRICT

Reports coding standards recommendations to ensure compatibility with future versions of PHP.

Numeric Values (Bitwise OR combinations):

You can combine error constants using the bitwise OR operator (|) to report multiple types of errors. For example:

To report all errors except notices:

php_flag display_errors on
php_value error_reporting E_ALL & ~E_NOTICE

To report fatal errors and warnings but not notices:

php_flag display_errors on
php_value error_reporting E_ERROR | E_WARNING

Conclusion

Congrats! Now, you’ve successfully learned about how to disable or partially disable PHP error reporting using the .htaccess file.