Ubuntu – Using apache rewrite modules without .htaccess file

apache-2.2mod-rewriteUbuntu

I have just completed this tutorial (and afew others) on how to use mod_rewrite with apache: http://www.workingwith.me.uk/articles/scripting/mod_rewrite . However, they all focus on using the .htaccess file to rewrite URLs

How can you use this rewrite engine module from the apache.conf / httpd.conf files or just from within the '/etc/apache2/sites-enabled' directory itself… ? Examples of any additional syntax needed on how to do this would be useful.

I have root access to my system so I would prefer to avoid using .htaccess files if at all possible. My system is Ubuntu-Server 10.04

Best Answer

Syntax is the same, but you have to make sure that you put your rules in the correct location within the httpd.conf file (or vhosts.conf or whatever is appropriate for your distro) depending on your requirements.

So if your rewrite rule is specific to a particular Virtual Host, then the rewrite rule would go in the container for that Virtual Host. If the rule is global (e.g. affects all sites), then you can put it anywhere in the httpd.conf file.

Documentation on mod_rewrite and context should be useful references for this. An Apache book is worth investing in if you will be doing a lot of this!

Out of interest, why do you want to avoid using .htaccess files for this? Changes in the .htaccess files are immediate, whereas changes in httpd.conf etc require apache restart to be effective.