If you have installed Apache2 web server via apt-get or aptitude on Debian or Ubuntu systems, it has mod_rewrite module installed, but not enabled by default. After Apache2 installation, you need to enable mod_rewrite explicitly in order to enjoy its benefit.
What is mod_rewrite?
Apache2 web server boasts of extensible features which are realized by the notion of pluggable modules. When building Apache2, you compile a set of modules you think are necessary, into it. One such module is called mod_rewrite which is responsible for rewriting website URLs at the server side. For example, when user asks for "http://myserver.com/my_category/my_post.html", the requested URL is translated by mod_rewrite to "http://myserver.com/post.php?category=100&post=200", which is then handled by the web server.
Why use mod_rewrite?
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 with mod_rewrite. Also, it can help hide any sensitive information such as query strings from URL requests, and hence can enhance website safety.
How to enable mod_write on Apache2
The default installation of Apache2 comes with mod_rewrite installed. To check whether this is the case, verify the existence of /etc/apache2/mods-available/rewrite.load.
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
To enable and load mod_rewrite, do the rest of steps.
The above command will create a symbolic link in /etc/apache2/mods-enabled.
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 "AllowOverride all".
Finally, restart Apache2.
Subscribe to Xmodulo
Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.
Did you find this tutorial helpful? Then please be generous and support Xmodulo!
Latest posts by Dan Nanni (see all)
- How to install Suricata intrusion detection system on Linux - September 3, 2015
- How to switch from NetworkManager to systemd-networkd on Linux - August 31, 2015
- How to set up a system status page of your infrastructure - August 25, 2015