Link to home
Start Free TrialLog in
Avatar of datastarstar
datastarstar

asked on

How to use mod_rewrite to redirect a URL

I'm trying to find the best way of accomplishing the following:

I have 2 separate web servers, let's call them abc.com and xyz.com.

The server hosting xyz.com is being decommissioned, but there are still active links pointing to it that my customers may continue to use.

Some of the customer links point directly to a perl script with embedded variables, something like this:
https://www.xyz.com/perl/scriptname.pl?var1=1&var2=1

Once I point the xyz.com domain to the server hosting abc.com, I'd like the above URL to be redirected to:
https://www.abc.com/perl/scriptname.pl?var1=1&var2=1

It makes no difference to me whether the end users sees the change in domain name, but I don't want them to get an SSL warning or error.

Is the best way to handle this to use a rewrite rule, an alias, or some other method? Please be as specific as possible with rewrite rules -- my skills are beginner in using mod_rewrite.

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of datastarstar
datastarstar

ASKER

The SSL cert on the old server is still valid -- can I just move that to the new server or does it have to be reissued? And is it possible to have certificates for both domain names in the same crt file?
You can just move everything.

And is it possible to have certificates for both domain names in the same crt file?
No, each cert needs to be seperate
Ok, I'm a little confused about this part. I will have no need to segregate the two sites on the new server. I was planning to just point the old domain (xyz.com) to the same IP of the server hosting abc.com.  Can I use a ServerAlias in my apache config in the same virtualhost for xyz.com? How then would I specify the location of separate SSL certificate files?

I'm thinking my virtualhost directive would look something like this:
<VirtualHost xxx.xxx.xxx.xxx:443>
    ServerName abc.com
    ServerAlias xyz.com
    SSLEngine on
    SSLCertificateFile       /etc/httpd/conf/ssl/abc.crt
    SSLCertificateKeyFile    /etc/httpd/conf/ssl/ssl.key
</VirtualHost>
Ok you can point both domains to the same document root, then in your htaccess setup the redirect condition based on the old domain name
But you can't have one cert for two different domains which is where you are stuck since you are using SSL for the site.
What if I pointed xyz to a different IP on the new box and and had a virtualhost section for xyz that used the same document root as abc but pointed to a different ssl certificate? Would that work?
That's what I was saying above.
Got it -- thanks for your help!