mod_rewrite is essential if you’re going to write RESTful web services. Here are the steps I went through to troubleshoot my installation:
- Ensure you included mod_rewrite in your apache installation. For gentoo, you can use [eix www-servers/apache] – Gentoo’s apache2_modules_rewrite flag is enabled for apache, looks good.
- Test to see if it is being loaded. I created a dummy page phpinfo.php with the contents [<?php phpinfo(); ?>], to see what PHP had to say about it. Search for mod_rewrite – yep, there it is, good. If not, make sure it’s loaded in httpd.conf, the load line may be commented out.
- Now make sure it’s enabled for the path you’re using. The apache directive is [RewriteEngine On], and it has to be somewhere in your httpd.conf or an included file. In my case I use virtual hosts. According to Apache docs, I needed to add both of these to the top level of my virtual host directive:
RewriteEngine On RewriteOptions Inherit
- The mod_rewrite rules I’m dealing with are all in .htaccess files. In that case you have to make sure you’ve turned on the switch that allows .htaccess files to override your settings. Basically, you’ll need [AllowOverride All] enabled for the path where you want to use .htaccess files.
- Finally, make sure your .htaccess settings and rules look good. Here’s an example I pulled from another good troubleshooting blog entry:
cat .htaccess Options +FollowSymLinks RewriteEngine On RewriteRule ^alice.html$ bob.html RewriteRule ^bob.html$ alice.html
It should force bob’s page to load when you request alice’s, and vice versa. Nice simple little test.
Once I went through this list, I was good to go.
[…] free the bird, leave the pane behind « Troubleshooting Apache mod_rewrite […]