
The .htaccess file is a configuration file used by the Apache web server to override default server settings for a specific directory or subdirectory. It allows webmasters to customize the behavior of the server without having to modify the global configuration file.
The .htaccess file can be used to set up password protection for a directory, redirect URLs, set custom error pages, define MIME types, enable server-side includes, and much more. It uses a simple syntax based on directives, which specify a particular action that the server should take.
It’s important to note that not all web hosts allow the use of .htaccess files, so you should check with your hosting provider before attempting to use one. Additionally, improperly configuring an .htaccess file can cause errors or security vulnerabilities, so it’s important to understand the syntax and use it carefully.
Start by opening up the Apache virtual hosts file called 000-default.conf, but yours may have a different name. You can use any editor such as nano or gedit or vi/vim for editing this configuration file.
Command: nano /etc/apache2/sites-enabled/000-default.conf
The set of directives that can be used in .htaccess files are established in the main site configuration via the AllowOverride directive, inside a <Directory> stanza; for example, to allow the use of all possible directives we would write something like:
<Directory /var/www/html>
AllowOverride All
</Directory>
The instructions will be applied to .htaccess files found in the specified directory and all its subdirectories. Let’s also check for syntax errors before doing so:
Command: apachectl configtest
For the changes to take effect, we will need to restart the Apache server.
Command: systemctl restart apache2
Next, create your .htaccess file in the directory specified earlier, and write your rules there. For example:
Redirect permanent / https://techhyme.com/
Save your changes and exit the file when done.
Navigate to your website to make sure the instructions in your .htaccess file are working as intended.
You may also read:
- How To Check Which Apps are Sending Information
- How To Use chattr Command in Linux
- [Two Methods] Force Linux User to Change Password at Next Login
- How To Install The WinDbg Windows Debugging Tool
- Getting Started with Apache Solr on Ubuntu
- Understanding OpenSSL Commands – A Comprehensive Guide
- How To Check SSL Certificate Expiry Date from Certificate File
- How To Install Apache Tomcat on Ubuntu 22.04 LTS
- How To Compress Files Faster Using Pigz on Ubuntu Linux
- A Step-by-Step Guide to Setting up Nginx and SSL with Certbot
- Mastering Chage Command – Examples and Usage
- How to Save cURL Output to a File
- Exploring the Finger Command in Linux
- How to List USB Devices in Ubuntu
- 5 Windows 11 Tricks You Should Try
- How To Change Default Search Engine in Microsoft Edge to Google
- 5 Methods to Clear the Recycle Bin in Windows 11
- How to Close Open Ports in Ubuntu
- How to Install and Use Pip in Ubuntu
- How To Check Ubuntu Version – 5 Different Ways