27
2009
Enable mod_rewrite in Ubuntu
Mod_rewrite is an apache module which enables rewriting of urls requested by client before the pages are fetched by apache. For example www.site.com/products.php?code=459 can be written as www.site.com/products/459 or www.site.com/products/459.html . The second url is re-written into the first one by mod_rewrite using rewrite rules specified in the .htaccess file.
To enable the mod_rewrite :
sudo a2enmod rewrite
To disable this module :
sudo a2dismod rewrite
Next edit the file :
/etc/apache2/sites-enabled/000-default or /etc/apache2/sites-available/default
Look for the section :
<directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </directory>
Replace the AllowOverride None with AllowOverride FileInfo as :
<directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride FileInfo Order allow,deny allow from all </directory>
Now restart apache
sudo /etc/init.d/apache2 restart
Now place an .htaccess file in say /var/www/ folder to test mod rewrite
To test whether mod_rewrite is working or not , fill the .htaccess file with some garbage text save and then open some file of that folder in the browser. You should get a 500 Internal Server Error and a .htaccess error in the apache log file. This shows that now mod_rewrite is enabled.
Now put some rewrite rules in the .htaccess file
RewriteEngine on RewriteRule ^([0-9]+)\.html$ index.php?id=$1
which should replace a folder/23.html to folder/index.php?id=23 for example.
Resources :
1. http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
2. http://httpd.apache.org/docs/1.3/howto/htaccess.html
3. http://httpd.apache.org/docs/1.3/configuring.html#htaccess
4. http://httpd.apache.org/docs/2.2/howto/htaccess.html
5. http://wiki.apache.org/httpd/DistrosDefaultLayout
Popularity: 4% [?]
Related Posts
Subscribe
Recent Posts
- Login into phpmyadmin without username and password
- 10+ tips to localise your php application
- 40+ Techniques to enhance your php code – Part 3
- 40+ Techniques to enhance your php code – Part 2
- 40+ Techniques to enhance your php code – Part 1
- CSSDeck – Collection of Pure CSS Creations
- Execute shell commands in PHP
- Php get list of locales installed on system
- Sound cracking in Ubuntu 11.10
- PHP script to perform IP whois
An article by





I love you man! I spent hours tweaking config files and modules, and this line saved me
“AllowOverride FileInfo”
Instead of allowing all, do this. Worked for me. <3
Awesome! That fixed a problem that had cost me hours of frustration. Thanks!
It worked!!
Thanks.