LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   apache rewrite keep wildcard prefix change domain (https://www.linuxquestions.org/questions/linux-server-73/apache-rewrite-keep-wildcard-prefix-change-domain-4175574566/)

sir-lancealot 03-10-2016 08:39 PM

apache rewrite keep wildcard prefix change domain
 
I think I have found every variable possible, even trying to figure out the variables, but we are moving domains (olddomain.com) over to newdomain. All the clients have their own prefix, so company1.olddomain.com works. We have newdomain.com setup.

The codebase is the same, I have separate vhosts for logging, I just want to say;
redirect company1.olddomain.com -> company1.newdomain.com. I cant search for company1 as we have hundreds, so just want to say ;
*.olddomain.com redirect to $1.newdomain.com

Every variable keeps dumping me at newdomain.com root.

Thanks for such a simple but annoying question.

I have the following;

Quote:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^olddomain\.com$ [NC]
RewriteRule ^(.*)$ http://$1.newdomain.com [R=301,L]
That does redirect but to simply .newdomain.com

So it really just seems to need the variable for the prefix which I cant find. I reconfirmed by sticking the rule to say RewriteRule ^(.*)$ http://x.newdomain.com [R=301,L]
and sure enough the browser redirects to http://x.newdomain.com so I just need the first part of the %{HTTP_HOST} I believe.

bathory 03-11-2016 02:32 AM

Hi,

You can use:
Code:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(.*).olddomain.com$ [NC]
RewriteRule (.*) http://%1.newdomain.com$1 [R=301,L]

Regards

sir-lancealot 03-11-2016 07:30 AM

Now that is something I will never forget! I have looked everywhere for those variables, and I knew some genius would just say oh it's %1 !!!!

Thanks so much, worked perfect!


All times are GMT -5. The time now is 08:36 AM.