After 5 days of reading the Mod_Rewrite documents, and a little bit of time refreshing myself on how Perl handles Regex, I finally came up with my rewrite rule that works. What I was trying to do was create a rewrite rule that rewrote
www.example.com to
www/example.com/my_servlet/. The part that made it sort of hard was that I have multiple domains, so I had to make sure to exclude those and not break anything else.
So step by step:
Create a new directory:
mkdir /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/VirtualHosts/
The second thing was to copy /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/VirtualHosts/26RewriteTraceAndTrack to my newly created directory.
I opened 26RewriteTraceAndTrack, and made it look like this:
{
$OUT =<<'HERE';
RewriteEngine on
RewriteLog /etc/httpd/logs/rewrite.log
RewriteLogLevel 1
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP_HOST} !^(.*)www\.example2.com(.*)
RewriteCond %{REQUEST_URI} !^(.*)webmail(.*)
RewriteRule ^(.*)$ http://www.example1.com/my_servlet/ [L]
HERE
}
The first three lines are pretty self explanatory; turn on the rewrite engine, tell where the rewrite.log is located, and set logging level (9 is the highest).
The first RewriteCond is to make sure that there is nothing after the domain name. I had a hard time with this part because I didn't realize that even if the REQUEST_URI was blank, it still held a back-slash.
The second rewrite condition was to make sure that I excluded all other domains except the one that I want. I only show one example here, but the rule could be repeated for multiple exclusions.
The third rewrite rule is now redundant. I added it in there to make sure I excluded any domains that were in the format of
www.example.com/webmail.I didn't want to accidentally break access to my webmail. In reality, this condition could be removed.
The rewrite rule says, in a nutshell, no matter what I have, replace it with
http://www.example1.com/my_servlet/. Because of the previous conditions that excluded all other possibilities, I know what I have left is what I want to replace. The [L] at the end signals mod_rewrite to not proess any more rules.
Then I did:
expand-template /etc/httpd/conf/httpd.conf
/etc/rc.d/init.d/httpd-admin restart
/etc/rc.d/init.d/httpd-e-smith restartI'm not sure if those last two lines are the proper way to restart apache, but it doesn't seem to have broken anything to this point.