To control file extensions using an `.htaccess` file, you can use Apache's mod_rewrite module to rewrite URLs and enforce specific file extensions. Here's an example of how you can achieve this:
1. Create or edit the `.htaccess` file in the root directory of your website.
2. Add the following lines to the `.htaccess` file:
```apache
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
```
In the above example, the rule `^([^\.]+)$` matches any URL segment that doesn't contain a dot (.), which indicates a file extension. The rule then appends `.php` to the URL, effectively adding the PHP file extension.
You can modify the rule according to your needs. For example, if you want to enforce the `.html` file extension, you would replace `$1.php` with `$1.html`.
3. Save the `.htaccess` file.
After applying the changes, any URL segment without an extension will automatically have the desired extension appended. For example, if someone requests `example.com/page`, it will be internally rewritten to `example.com/page.php`. This way, the server can serve the appropriate file.
Remember to ensure that the mod_rewrite module is enabled on your Apache server. Additionally, make sure that you have AllowOverride set to at least FileInfo or All in the appropriate Apache configuration to allow the use of `.htaccess` files.