You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Pete Nesbitt <pn...@fivermedia.com> on 2009/05/20 22:04:27 UTC
[users@httpd] Rewrite: modify http_host for many subdomains
Hi,
We are changing one of our domain names which has about 150 host/subdomains.
Apache version is 2.0.52 on RHEL4
Current http_host's would look something like this:
service1.old-domain.com
service2.old-domain.com
host1.subdom1.old-domain.com
etc...
I need to make them read:
service1.new-domain.com
service2.new-domain.com
host1.subdom1.new-domain.com
From what I can see I would need to add a separate rewrite set for each host
within the old domain:
RewriteCond %{HTTP_HOST} ^service1\.old-domain\.com$ [NC]
RewriteRule ^(.*)$ service1.new-domain.com$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^service2\.old-domain\.com$ [NC]
RewriteRule ^(.*)$ service2.new-domain.com$1 [R=301,L]
etc...
I am searching for a method to do this with a single rule.
I have tried adding shell type variable substitution but that fails:
OLDDOM=%{HTTP_HOST}
NEWDOM=`echo %{HTTP_HOST}|sed s/old-domain/new-domain/`
RewriteRule ^(.*)$ ${NEWDOM}$1 [R=301,L]
Any help would be appreciated.
Thanks.
Pete
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Rewrite: modify http_host for many subdomains
Posted by Pete Nesbitt <pn...@fivermedia.com>.
On Wednesday 20 May 2009 01:43:00 pm Justin Pasher wrote:
> Pete Nesbitt wrote:
> > Hi,
> > We are changing one of our domain names which has about 150
> > host/subdomains. Apache version is 2.0.52 on RHEL4
> >
> > Current http_host's would look something like this:
> > service1.old-domain.com
> > service2.old-domain.com
> > host1.subdom1.old-domain.com
> > etc...
> >
> > I need to make them read:
> > service1.new-domain.com
> > service2.new-domain.com
> > host1.subdom1.new-domain.com
> >
> > From what I can see I would need to add a separate rewrite set for each
> > host within the old domain:
> > RewriteCond %{HTTP_HOST} ^service1\.old-domain\.com$ [NC]
> > RewriteRule ^(.*)$ service1.new-domain.com$1 [R=301,L]
> >
> > RewriteCond %{HTTP_HOST} ^service2\.old-domain\.com$ [NC]
> > RewriteRule ^(.*)$ service2.new-domain.com$1 [R=301,L]
> > etc...
>
> Assuming that all of them end in old-domain.com, something like this
> should work (untested, but the concept should work):
>
> RewriteCond %{HTTP_HOST} (.*)\.old-domain\.com$ [NC]
> RewriteRule ^/(.*) http://%1.new-domain.com/$1 [R=301,L]
>
>
> --
> Justin Pasher
>
That works perfectly.
Thanks a lot Justin!
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Rewrite: modify http_host for many subdomains
Posted by Justin Pasher <ju...@newmediagateway.com>.
Pete Nesbitt wrote:
> Hi,
> We are changing one of our domain names which has about 150 host/subdomains.
> Apache version is 2.0.52 on RHEL4
>
> Current http_host's would look something like this:
> service1.old-domain.com
> service2.old-domain.com
> host1.subdom1.old-domain.com
> etc...
>
> I need to make them read:
> service1.new-domain.com
> service2.new-domain.com
> host1.subdom1.new-domain.com
>
> From what I can see I would need to add a separate rewrite set for each host
> within the old domain:
> RewriteCond %{HTTP_HOST} ^service1\.old-domain\.com$ [NC]
> RewriteRule ^(.*)$ service1.new-domain.com$1 [R=301,L]
>
> RewriteCond %{HTTP_HOST} ^service2\.old-domain\.com$ [NC]
> RewriteRule ^(.*)$ service2.new-domain.com$1 [R=301,L]
> etc...
>
Assuming that all of them end in old-domain.com, something like this
should work (untested, but the concept should work):
RewriteCond %{HTTP_HOST} (.*)\.old-domain\.com$ [NC]
RewriteRule ^/(.*) http://%1.new-domain.com/$1 [R=301,L]
--
Justin Pasher
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Rewrite: modify http_host for many subdomains
Posted by Tom Evans <te...@googlemail.com>.
On Wed, 2009-05-20 at 13:04 -0700, Pete Nesbitt wrote:
> Hi,
> We are changing one of our domain names which has about 150 host/subdomains.
> Apache version is 2.0.52 on RHEL4
>
> Current http_host's would look something like this:
> service1.old-domain.com
> service2.old-domain.com
> host1.subdom1.old-domain.com
> etc...
>
> I need to make them read:
> service1.new-domain.com
> service2.new-domain.com
> host1.subdom1.new-domain.com
>
> From what I can see I would need to add a separate rewrite set for each host
> within the old domain:
> RewriteCond %{HTTP_HOST} ^service1\.old-domain\.com$ [NC]
> RewriteRule ^(.*)$ service1.new-domain.com$1 [R=301,L]
>
> RewriteCond %{HTTP_HOST} ^service2\.old-domain\.com$ [NC]
> RewriteRule ^(.*)$ service2.new-domain.com$1 [R=301,L]
> etc...
>
> I am searching for a method to do this with a single rule.
>
> I have tried adding shell type variable substitution but that fails:
> OLDDOM=%{HTTP_HOST}
> NEWDOM=`echo %{HTTP_HOST}|sed s/old-domain/new-domain/`
> RewriteRule ^(.*)$ ${NEWDOM}$1 [R=301,L]
>
> Any help would be appreciated.
>
> Thanks.
> Pete
>
I wrote a module to do this, to avoid having to keep adding rewrite
rules, see this mail
http://mail-archives.apache.org/mod_mbox/httpd-users/200904.mbox/%
3C1240428167.3533.7.camel@localhost%3E
Cheers
Tom
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Rewrite: modify http_host for many subdomains
Posted by Pete Nesbitt <pn...@fivermedia.com>.
On Wednesday 20 May 2009 01:23:38 pm André Warnier wrote:
> Pete Nesbitt wrote:
> > Hi,
> > We are changing one of our domain names which has about 150
> > host/subdomains. Apache version is 2.0.52 on RHEL4
> >
> > Current http_host's would look something like this:
> > service1.old-domain.com
> > service2.old-domain.com
> > host1.subdom1.old-domain.com
> > etc...
> >
> > I need to make them read:
> > service1.new-domain.com
> > service2.new-domain.com
> > host1.subdom1.new-domain.com
> >
> > From what I can see I would need to add a separate rewrite set for each
> > host within the old domain:
> > RewriteCond %{HTTP_HOST} ^service1\.old-domain\.com$ [NC]
>
> Any reason why you don't just use "ServerAlias" ?
>
> <VirtualHost *:80>
> ServerName service1.new-domain.com
> ServerAlias service1.old_domain.com
> ...
> </VirtualHost>
>
> As long as "service1.new-domain.com" and "service1.old-domain.com"
> resolve to the same IP address in DNS, that should be all that's
> required for the migration.
>
Sorry, I should have included a bit more info.
I have a single VirtualHost section (config file actually) which lists all the
entries as ServerAlias's.
Part of the requirement is for SEO (search engine optimization) to have 301
rewrites for each old http_host in order for the search engines to see only
one url for each content area. Without the 301, then for example, google
see's service1.old-domain & service1.new-domain as different destinations and
the rankings are cut in half (if it was 50/50 hits)
-Pete
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Rewrite: modify http_host for many subdomains
Posted by André Warnier <aw...@ice-sa.com>.
Pete Nesbitt wrote:
> Hi,
> We are changing one of our domain names which has about 150 host/subdomains.
> Apache version is 2.0.52 on RHEL4
>
> Current http_host's would look something like this:
> service1.old-domain.com
> service2.old-domain.com
> host1.subdom1.old-domain.com
> etc...
>
> I need to make them read:
> service1.new-domain.com
> service2.new-domain.com
> host1.subdom1.new-domain.com
>
> From what I can see I would need to add a separate rewrite set for each host
> within the old domain:
> RewriteCond %{HTTP_HOST} ^service1\.old-domain\.com$ [NC]
Any reason why you don't just use "ServerAlias" ?
<VirtualHost *:80>
ServerName service1.new-domain.com
ServerAlias service1.old_domain.com
...
</VirtualHost>
As long as "service1.new-domain.com" and "service1.old-domain.com"
resolve to the same IP address in DNS, that should be all that's
required for the migration.
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org