3

Having asked a long and convoluted question earlier, I now have some code here using RedirectPermanent that I need help with.

We're merging an old site into the new one, and don't care about mapping all the ancient urls to anywhere on the new site, so all of it should be permanently redirected to a special index.php that will decide if/where to redirect with php.

The exception is one subdomain, it should do the same thing, but to a different index.php.

This is the "pseudo-config" I'm trying to accomplish - slight variations will work, but I can't get it to ignore the full path of the request, and unconditionally go to my choice of index.php with the querystring.

#Subdomain from old site:
#Process querystring from root\oldsite\subdomain\index.php
<VirtualHost *:80>
    ServerName subdomain.oldsite.com
    RedirectPermanent / http://www.newsite.com/oldsite/subdomain/index.php  
</VirtualHost>

#ALL other requests of any kind regardless of path
#Process querystring from root\oldsite\index.php
# Must show www.newsite.com, NOT www.oldsite.com
<VirtualHost *:80>
    ServerName oldsite.com
    ServerAlias www.oldsite.com
    RedirectPermanent / http://www.newsite.com/oldsite/index.php    
</VirtualHost>

The DNS has been set so that everything from the old site goes to this server, and these are the first VirtualHost entries in the config file. How do i modify this code to go to the given index.php regardless of the path.

www.oldsite.com                       ==> www.newsite.com\oldsite\index.php
www.oldsite.com/forum/anything/else   ==> www.newsite.com\oldsite\index.php
www.oldsite.com/faq/category/chosen   ==> www.newsite.com\oldsite\index.php
www.oldsite.com/about/us/index.php    ==> www.newsite.com\oldsite\index.php
subdomain.oldsite.com/anthing         ==> www.newsite.com\oldsite\subdomain\index.php

1 Answer 1

5

Redirect is not the correct one to use for what you seek. Redirect redirects "all" and "appends that all" to the destination, but you want a final single destination, so.. use this instead:

RedirectMatch ^ http://newsite.example.com/oldsite/subdomain/index.php

This will redirect everything to the destination you specify, without appending anything else.

3
  • Thanks for this. Is there a way to capture what the original url and querystring was for processing in that index.php
    – GDP
    Commented Jan 10, 2017 at 15:36
  • this other question is not a simple redirect, just pass the request to the next domain for it to handle. I would indeed use a Redirect / http://newsite.example.com/ to make sure the original request gets passed along and in the destination I would just have a FallbackResource /path/to/index.php or something of that fashion, to make sure the main controller gets what has been requested. Commented Jan 11, 2017 at 8:26
  • 1
    And to use HTTP 301 instead of 302, you can add 301 after RedirectMatch: askapache.com/htaccess/…
    – baptx
    Commented Apr 1, 2021 at 23:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .