We help IT Professionals succeed at work.

Hoist the colors! We’ve added location flags to usernames sitewide, so it's easier to connect with the global community on EE. View My Profile

x

apache rewrite rules old-dmain to new-domian

89 Views
Last Modified: 2019-02-06
apache rewrite rules to redirect http(s) olddomian.com to newdomain.com
i made a custom  VirtualHost .conf file for apache for my old domian to redirect every request to httpS new domain but it isn't working...?
i get either the old host or some an invalid URL... both FireFox and Chome show errors like this:
The owner of OldDomian.com has configured their website improperly. To protect your information from being stolen, Firefox has not connected to this website. The certificate is only valid for NewDomain.com.

a copy of the apache.conf VirtualHost config:
<VirtualHost 129.125.125.128:80>
ServerName  OldSiteHost.com
ServerAlias www.OldSiteHost.com
ServerAlias OldSiteHost.com

RewriteEngine on
RewriteCond %{SERVER_NAME} =OldSiteHost.com [OR]
RewriteCond %{SERVER_NAME} =www.newcorp.OldSiteHost.com [OR]
RewriteCond %{SERVER_NAME} =newcorp.OldSiteHost.com [OR]
RewriteCond %{SERVER_NAME} =www.OldSiteHost.com
RewriteRule ^ https://NewSiteHost.com/ [END,NE,R=permanent]

</VirtualHost>

Open in new window

Comment
Watch Question

David FavorFractional CTO
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Likely better to take a completely different approach.

You'll use 2x config files. One will be for new site. One will be for old site.

Note: Do not use R=301/permanent use R=302 instead.

Using a permanent redirect will cause far more problems than you imagine.

Always use a 302 (temp redirect) to avoid complex browser caching problems for which there is no recovery. If you think you must use a 301, then only change 302 -> 301 after you've thoroughly tested your redirects.

Config file setups...

1) Your new site config will never mention your old site.

2) Your old site config will have exactly one redirect, from the terminal/final site URL to your new site URL.

Author

Commented:
i do have 2 separate config files one for each virtual host below are the sample configs

Old Site

<VirtualHost 129.125.125.128:80>
ServerName  OldSiteHost.com
ServerAlias www.OldSiteHost.com
ServerAlias OldSiteHost.com
RewriteEngine on
RewriteCond %{SERVER_NAME} =OldSiteHost.com [OR]
RewriteCond %{SERVER_NAME} =www.new.OldSiteHost.com [OR]
RewriteCond %{SERVER_NAME} =new.OldSiteHost.com [OR]
RewriteCond %{SERVER_NAME} =www.OldSiteHost.com
RewriteRule ^ https://NewSiteHost.com/ [END,NE,R=302]
</VirtualHost>

Open in new window

NEW Site

<VirtualHost 129.125.125.128:80>
ServerName  NewSiteHost.com
ServerAlias www.NewSiteHost.com
ServerAlias NewSiteHost.com
bla bla bla
</VirtualHost>

Open in new window

David FavorFractional CTO
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
In old site file... remove line #4 + #7 + #8.

In new site file... remove line #4.

Having a ServerName + ServerAlias both match likely results in undefined behavior.

Might work correctly now.

Might work far differently in the future.

Likely this will be an error in the future, because...

ServerName  NewSiteHost.com - this means serve content.

ServerAlias NewSiteHost.com - this means to return a 301 for NewSiteHost.com which is an error or a conflict with the ServerName directive.
David FavorFractional CTO
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Try removing the records I mentioned + see if you problem resolves.
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.