.htaccess Experts - Two Domains, One Server

I hope someone can direct me to a comprehensive tutorial on these things. And no, I don’t fully understand the Apache documentation. Too much info.

Basically, I’ve got two domains (www.mydomain.info; www.mydomain.com). What I’m trying to accomplish is that all requests for the .info domain be redirected to the .com domain, AND that the .com domain be reflected in the URL in the browser’s address bar.

As a sidebar, I’d also like to know more about wild-cards and various switches (like [NC] vs. [R] and such).

Depends a bit on how the two domains are set up currently. If the two domains are serving different directory trees, the rules are simple, just put this in the base directory .htacces (or main config file) for the .info domain:


RewriteEngine On
RewriteBase   /     # not sure if you really need this
RewriteRule ^/?(.*) http://mydomain.com/$1 [L,NE] 

No need for [R], because a rewrite to another host is always an external redirect. You do need NE for correctly redirecting URLs that contain escaped characters. L is just there to be a bit more explicit that this is the only rewriting rule to apply.

If the two domains are served from the same tree, see the example configuration for ‘canonical host names’.

The wild cards in rewrite rules are extended regular expressions, which are extremely useful but it really takes a small book to explain them in detail. Check the wiki link I provided for some introduction material, or the Perl documentation on its regular expression syntax, which is mostly compatible with Apache’s.

Lots of the options for the rewriterule directive are only useful in very specific cases (like proxying a separate web server, or setting up some environments to be used by some underlying web application). For your kind of task, you really only need to know about NE, R and L.

Many thanks, SP. I’m already perusing the specific docs and have found more info that I needed.