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:
- SSH Enumeration and Penetration Testing – A Brief Guide
- How to Install Winlogbeat in Windows OS
- [Tutorial] How to Install MobSF on Kali Linux 2022.1
- How To Install Jenkins on Ubuntu Machine
- [Tutorial] How To Install Webmin in Ubuntu
- How to Install Apache Tomcat on Ubuntu Machine
- A Step-by-Step Guide to Installing the LAMP Stack on Ubuntu
- Find OS Version with 5 Different Methods in Windows PowerShell
- [Linux] MySQL: The Easy Way to Check Your Version
- How To Install Remmina in Ubuntu – A Remote Desktop Client
- Creating New Files and Directories Using Windows PowerShell New-Item CMDLET
- 18 Most Frequently Used Commands in Linux
- How to Install Apache Cassandra in Ubuntu
- Mount a Remote Filesystem over SSH with SSHFS
- How To Install and Configure Samba Server in Ubuntu
- Disable SMB3 Protocol With CMD and PowerShell in Windows 10
- [Linux] Scanning Open Ports With Netcat
- Four Ways To Show Mounted Drives on Linux System
- 3 Ways To Get the UUID of a Disk Partition in Ubuntu Linux
- DUF Command in Ubuntu Linux – Usage and Examples