LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-10-2016, 08:39 PM   #1
sir-lancealot
Member
 
Registered: Aug 2007
Posts: 346

Rep: Reputation: 31
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.

Last edited by sir-lancealot; 03-10-2016 at 09:23 PM.
 
Old 03-11-2016, 02:32 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,167
Blog Entries: 1

Rep: Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038
Hi,

You can use:
Code:
RewriteEngine On

RewriteCond %{HTTP_HOST} ^(.*).olddomain.com$ [NC]
RewriteRule (.*) http://%1.newdomain.com$1 [R=301,L]
Regards
 
Old 03-11-2016, 07:30 AM   #3
sir-lancealot
Member
 
Registered: Aug 2007
Posts: 346

Original Poster
Rep: Reputation: 31
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!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Will rewrite kernel with length prefix string make things faster lloydsu Linux - Kernel 6 06-23-2014 05:12 AM
[SOLVED] HTTPS in sub domain serves content from main domain. Wildcard SSL installed. amit.roy Linux - Server 17 11-25-2012 01:56 PM
avahi and wildcard prefix on domain mpapet Linux - Networking 0 10-28-2012 03:04 PM
Apache no-www to www domain rewrite after upgrade deesto Linux - Server 5 06-20-2012 12:16 PM
Apache 2 Rewrite One Domain To Another thunder04 Linux - Software 10 04-19-2006 01:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration