Last updated on October 16, 2020 by Dan Nanni
If you have installed Apache HTTP server via
aptitude on Ubuntu or Debian systems, it has
mod_rewrite module installed, but not enabled by default. After Apache web server installation, you need to enable
mod_rewrite explicitly in order to enjoy its benefit.
Apache HTTP web server boasts of extensible features which are realized by the notion of pluggable modules. When building Apache web server, you compile a set of modules you think are necessary, and built them into the web server. One such module is called
mod_rewrite which is responsible for dynamically rewriting website URLs at the server side. For example, when user asks for
http://myserver.com/my_category/my_post.html, the requested URL can be translated by
http://myserver.com/post.php?category=100&post=200, which is then handled by the web server's backend engine.
Webmasters generally use
mod_rewrite to improve user-friendliness and search engine friendliness of web sites by exposing more memorable and crawlable URLs to the world. Also, it can help hide any sensitive information such as query strings from URL requests, and hence enhance website safety.
The default installation of Apache2 comes with
mod_rewrite installed. To check whether this is the case, verify the existence of
$ cat /etc/apache2/mods-available/rewrite.load
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
To enable and load
mod_rewrite in Apache2 web server, do the rest of steps.
$ sudo a2enmod rewrite
The above command will create a symbolic link in
$ ls -al /etc/apache2/mods-enabled/rewrite.load
lrwxrwxrwx 1 root root 30 Dec 9 23:10 /etc/apache2/mods-enabled/rewrite.load -> ../mods-available/rewrite.load
Then open up the following file, and replace every occurrence of
AllowOverride None with
$ sudo vi /etc/apache2/sites-available/default
Finally, restart Apache2.
$ sudo service apache2 restart
$ sudo systemctl start apache2
This website is made possible by minimal ads and your gracious donation via PayPal or credit card
Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.
Xmodulo © 2021 ‒ About ‒ Write for Us ‒ Feed ‒ Powered by DigitalOcean