How to configure Apache rewrite rule-based request URL on Debian 12
- 00:30 cat /etc/os-release
- 00:38 cd /var/www/
- 00:47 ls -la
- 00:56 mkdir old-page
- 01:07 mkdir new-page
- 01:20 touch old-page/old.html
- 01:42 touch new-page/new.html
- 02:01 echo "old html file content" >> old-page/old.html
- 02:22 echo "new html file content" >> new-page/new.html
- 02:57 vim /etc/apache2/sites-available/000-default.conf
- 03:36 systemctl restart apache2
- 04:22 vim .htaccess
- 05:31 a2enmod rewrite
- 05:47 systemctl restart apache2
To Configure Apache Rewrite Rule Based Request URL On Debian 12
Introduction :
Apache Rewrite rules are directives utilized in .htaccess files or virtual host configurations to alter the URL of a requested resource prior to server processing. These rules allow for URL modifications based on defined patterns, conditions, and actions.
Procedure :
Step 1 : Check the OS version by using following command.
root@linuxhelp:~# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
Step 2 : Go to the Document root directory by using following command.
root@linuxhelp:~# cd /var/www/
Step 3 : Long list the files by using following command.
root@linuxhelp:/var/www# ls -la
total 12
drwxr-xr-x 3 root root 4096 Aug 19 18:19 .
drwxr-xr-x 13 root root 4096 Aug 19 18:19 ..
drwxr-xr-x 4 www-data www-data 4096 Sep 5 08:03 html
Step 4 : Create a directory by using following command.
root@linuxhelp:/var/www# mkdir old-page
Step 5 : Create another directory by using following command.
root@linuxhelp:/var/www# mkdir new-page
Step 6 : Create a file inside first created directory by using following command.
root@linuxhelp:/var/www# touch old-page/old.html
Step 7 : Create another file inside second created directory by using following command.
root@linuxhelp:/var/www# touch new-page/new.html
Step 8 : Input some content for the first file by using following command.
root@linuxhelp:/var/www# echo "old html file content" >> old-page/old.html
Step 9 : Input some content for the second file by using following command.
root@linuxhelp:/var/www# echo "new html file content" >> new-page/new.html
Step 10 : Make Document Root location in virtual host.
root@linuxhelp:/var/www# vim /etc/apache2/sites-available/000-default.conf
DocumentRoot /var/www/
<Directory /var/www/>
AllowOverride All
Require all granted
</Directory>
Step 11 : Restart Apache service by using following command.
root@linuxhelp:/var/www# systemctl restart apache2
Step 12 : Open firefox and search ip address with directory and file name

Step 13 : Create Dothtaccess file to create rewrite rule by using following command.
root@linuxhelp:/var/www# vim .htaccess
RewriteEngine On
RewriteRule ^old-page/(.*)$ /var/www/new-page/$1 [L]
Step 14 : Enable Apache rewrite module by using following command.
root@linuxhelp:/var/www# a2enmod rewrite
Module rewrite already enabled
Step 15 : Restart the Apache service by using following command.
root@linuxhelp:/var/www# systemctl restart apache2
Step 16 : Open Firefox and search IP address and direcory

Conclusion :
We have reached the end of this article. In this guide, we have walked you through the steps required to configure Apache rewrite rule based request URL on Debian 12. Your feedback is much welcome.
Comments ( 0 )
No comments available