?
Solved

Redirect multiple apache aliases to single url

Posted on 2011-10-24
6
Medium Priority
?
214 Views
Last Modified: 2012-05-12
Hi,

I have a site that has multiple apache aliases, so for example if you browser to sitec.com or www.siteb.com it is the same site as www.sitea.com handled by one enabled site in apache. I want to 301 redirect any site alias to www.sitea.com

I figure this can be done with .htaccess but I am not very good with creating the matching rules to get this working.

Thanks for your help.
0
Comment
Question by:jrm213jrm213
  • 3
  • 3
6 Comments
 
LVL 21

Expert Comment

by:Papertrip
ID: 37019715
http://httpd.apache.org/docs/2.0/mod/mod_alias.html#redirect

Redirect permanent / http://www.sitea.com

Open in new window

0
 
LVL 17

Author Comment

by:jrm213jrm213
ID: 37019762
Won't that cause a problem? ie. www.sitea.com will also hit that redirect, so won't it create a redirect loop?

basically I have this in apache site config

ServerName www.sitea.com
ServerAlias sitea.com www.siteb.com siteb.com www.sitec.com sitec.com www.sited.com sited.com www.sitee.com sitee.com

Open in new window


Alll of the server alias domains, and server name domain all are the same apache site. But no matter which one you go to I want the url to show www.sitea.com, so if you had bookmarked www.sitec.com/page1  it would 301 redirect to www.sitea.com/page1

does that make sense?
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 37019878
Yeah, my bad I overlooked the part of your question where you said you had aliases setup.  I will reply again after lunch, unless someone gets it before me.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 17

Author Comment

by:jrm213jrm213
ID: 37019895
Ok, no problem.

Thanks
0
 
LVL 21

Accepted Solution

by:
Papertrip earned 2000 total points
ID: 37020194
OK so if you want to keep all the ServerAlias entries instead of creating individual vhosts for them, then the following will work.
     RewriteEngine  on
     RewriteCond %{HTTP_HOST} !^www.sitea.com$ [NC]
     RewriteRule ^(.*)$ http://www.sitea.com/$1 [R=301,NC,L]

Open in new window


That is pretty basic and should be put into the VirtualHost config block where ServerName is listed.

Depending on how your website is configured (ie: aliases, .htaccess, Directory config blocks, etc), there could be some additional tuning required, but for "basic" 301 rewrites, that syntax will work just fine.
0
 
LVL 17

Author Comment

by:jrm213jrm213
ID: 37033264
Thanks, that worked for the aliases.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question