Htaccess File in PHP

Introduction

In this article I will explain ".htaccess" files in PHP. A ".htaccess" file can also be a robust tool for modifying your Apache configuration on a per-domain and even a per-directory level. Many content management systems place confidence in .htaccess files for configuring your web site. The complete filename of the file is ".htaccess", it isn't a file extension. As an example, you'd not create a file as "file.htaccess", it's simply ".htaccess". 
You can create a .htaccess file using any sensible text editor like TextPad, UltraEdit, Microsoft WordPad and similar (you cannot use Microsoft NotePad) and the .htaccess file is also used password protected.

Requirement

Before you start, be sure to have these:

  • You use of FTP and an FTP client with familiarly.
  • Plain text editor.

Creating the .htaccess files

You'll conjointly produce your own .htaccess file manually. Your .htaccess file must be a lucid text file. This suggests you wish to create it in an exceedingly text written material program capable of producing plain text files. 

  • You can use Notepad on a windows. That is one amongst your integral accessories.
  • You can use TextEdit on a windows Mac. You need to first open the TextEdit "Preferences" menu and, within the "New Document" section, choose "Plain text". Then, you'll begin a brand new document in TextEdit for your .htaccess file.

When you save your document, ensure you name it htaccess.txt, or something similar. If you save it as .htaccess, your computer can hide the file. This can be the result of files that begin with "." are thought of to be system files.

Uploading .htaccess File

You should transfer your file to the precise directory you would like it to change. Typically, this may be your hypertext mark-up language directory ("home/00000/domains/example.COM/html/") though you'll transfer it to any directory on your server likewise. Uploaded the file then rename it to .htaccess exactly.

At this time, the file might disappear from your FTP show, as a result of it currently has the format of a system file. Several FTP shoppers enable you to look at hidden files and folders if you change that feature. Check your FTP client documentation for directions.

PHP Values

Most PHP values are often set in your .htaccess file moreover as in your "php.ini" file. To use them in your .htaccess file, preface them with the subsequent line.

<?php
php_value;
?>

For example You could set the value.

<?php

php_value upload_max_filesize 16M;

?>

To check that your new PHP values are enforced, use a PHP info page, and check the native worth column.

<?php

// Show all information, defaults to INFO ALL

phpinfo();

?>

Error Reporting

Put the subsequent lines in your .htaccess file to alter complete error coverage. You'll change the value from E_ALL to any desired variety of error reporting

<?php

php_flag display_errors on;

php_value error_reporting E_ALL;

?>

Up Next
    Ebook Download
    View all
    Learn
    View all