• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

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
{{postValue.id}}

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 snap 1

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 snap 2

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.

Tags:
grayson
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

What is the purpose of Apache's mod_rewrite module?

A

The mod_rewrite module allows you to rewrite URLs based on various conditions, such as the Request URI, query parameters, HTTP method, etc. It's a powerful tool for manipulating Apache URLs.

Q

How do I enable the mod_rewrite module in Apache?

A

On Debian 12 (and similar systems), run sudo a2enmod rewrite to enable the module.
On other systems, check your Apache documentation for instructions on enabling mod_rewrite.

Q

What is the syntax for writing RewriteRule directives?

A

RewriteRule [flags]
Here:
• matches the URL against a regular expression.
• specifies the new URL to use.
• [flags] optional flags can control the rewrite process.

Q

What is the difference between R=301 and R=302?

A

R=301 indicates a permanent redirect ( Moved Permanently), while R=302 indicates a temporary redirect. Choose carefully, as permanent redirects can have SEO implications!

Q

How do I block URLs with certain patterns using RewriteRule?

A

Use the [F] flag to forbid access to URLs that match the pattern.
RewriteRule ^/example/block-me$ - [F]
This will block all requests to /example/block-me.

Load more

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help keel johnston ?
Unhide the folders on windows Explorer

Give any solutions to unhide folder using command prompt?

forum3

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.