Solved

How to use mod_rewrite to redirect a URL

Posted on 2014-12-22
8
122 Views
Last Modified: 2014-12-23
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!
0
Comment
Question by:datastarstar
  • 4
  • 4
8 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40513534
Copy everything to the new server - i.e. the old domain
Update the DNS
When the DNS has propogated (upto 48 hours) you can disable the old server and initiate an htaccess on the new server to redirect the old domain to the new domain

But if the old sites ssl cert is expiring then it won't work once it has expired, so you would need to ensure you update it while there may still be links out there.
0
 

Author Comment

by:datastarstar
ID: 40513698
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?
0
 
LVL 58

Expert Comment

by:Gary
ID: 40513716
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
0
 

Author Comment

by:datastarstar
ID: 40513813
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>
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 58

Expert Comment

by:Gary
ID: 40513826
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.
0
 

Author Comment

by:datastarstar
ID: 40514720
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?
0
 
LVL 58

Expert Comment

by:Gary
ID: 40514893
That's what I was saying above.
0
 

Author Comment

by:datastarstar
ID: 40514965
Got it -- thanks for your help!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now