LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-17-2013, 11:14 PM   #1
SernOne
Member
 
Registered: Oct 2012
Posts: 33

Rep: Reputation: Disabled
Forwarding mutlitable domains


I have a bunch of domains .com .co .info, etc. I want them all to point forward to .com when you go to any of them I know this is possible through the .htaccess file but I am having trouble finding documentation on this. Can anyone help me with this is driving me mad lol

thanks
 
Old 04-18-2013, 02:49 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,526

Rep: Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503
Hi,

You didn't mention your webserver, but you said about .htaccess I guess it's apache.
In this case, assuming that you have the correct dns entries, so each .com, .co, .info resolve to the IP of your apache, all you have to do is to use:
Code:
ServerName www.domain.com
ServerAlias www.domain.co www.domain.info
Regards

Last edited by bathory; 04-18-2013 at 02:53 AM. Reason: typos
 
Old 04-18-2013, 03:20 PM   #3
SernOne
Member
 
Registered: Oct 2012
Posts: 33

Original Poster
Rep: Reputation: Disabled
Yes I have done that however i was looking for if someone goes to example.co it will forward to example.com instead.
 
Old 04-18-2013, 04:14 PM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,526

Rep: Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503
Quote:
Originally Posted by SernOne View Post
Yes I have done that however i was looking for if someone goes to example.co it will forward to example.com instead.
Do you want to change the hostname in the URL, so it becomes example.com?
In this case in addition to the above, you should use mod_rewrite either in .htaccess or in the apache config file:
Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^example.com [NC]
RewriteRule ^/(.*) http://example.com/$1 [R=301]
 
Old 04-18-2013, 08:36 PM   #5
SernOne
Member
 
Registered: Oct 2012
Posts: 33

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bathory View Post
Do you want to change the hostname in the URL, so it becomes example.com?
In this case in addition to the above, you should use mod_rewrite either in .htaccess or in the apache config file:
Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^example.com [NC]
RewriteRule ^/(.*) http://example.com/$1 [R=301]
I tried that but it didn't work what might i be doing wrong here

Code:
LoadModule rewrite_module modules/mod_rewrite.so
Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^example.com [NC]
RewriteRule ^/(.*) http://example.com/$1 [R=301]
When i go to example.info it still doesn't redirect to example.com , so basically to clear up some things I only have some cookie sessions that run off the .com address however instead of rewriting a bunch of new cookie sessions I'd rather just redirect all traffic over the .info .co .net and .org to go to the .com address.
 
Old 04-19-2013, 03:27 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,526

Rep: Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503Reputation: 1503
Quote:
I tried that but it didn't work what might i be doing wrong here
if you put the above in a .htaccess file in the docroot, you need to change slightly the rewriterule to:
Code:
RewriteRule (.*) http://example.com/$1 [R=301]
Also make sure that apache reads .htaccess files (check if the AllowOverride is set to All).
 
Old 04-19-2013, 04:57 AM   #7
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,171

Rep: Reputation: 752Reputation: 752Reputation: 752Reputation: 752Reputation: 752Reputation: 752Reputation: 752
You can also achieve this by creating a VirtualHost and doing the redirect directly in apache, this would be "lighter" as because there is no DocumentRoot apache doesn't have to read any files or traverse a path to find .htaccess files.

Example:

Code:
<VirtualHost 188.138.103.171:80>
  ServerName www.10tenths.com
  ServerAlias 10tenths.com

  ServerAlias www.10ths.com
  ServerAlias 10ths.com

  ServerAlias www.motorsport.xxx
  ServerAlias motorsport.xxx

  RedirectMatch 301 (.*) http://www.ten-tenths.com$1
</VirtualHost>
You can also add a logfile directive if you want to find out which of your domains or variations is being used.

Last edited by TenTenths; 04-19-2013 at 04:59 AM.
 
Old 04-19-2013, 03:32 PM   #8
SernOne
Member
 
Registered: Oct 2012
Posts: 33

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TenTenths View Post
You can also achieve this by creating a VirtualHost and doing the redirect directly in apache, this would be "lighter" as because there is no DocumentRoot apache doesn't have to read any files or traverse a path to find .htaccess files.

Example:

Code:
<VirtualHost 188.138.103.171:80>
  ServerName www.10tenths.com
  ServerAlias 10tenths.com

  ServerAlias www.10ths.com
  ServerAlias 10ths.com

  ServerAlias www.motorsport.xxx
  ServerAlias motorsport.xxx

  RedirectMatch 301 (.*) http://www.ten-tenths.com$1
</VirtualHost>
You can also add a logfile directive if you want to find out which of your domains or variations is being used.
Thank kind of works, but i get looping errors
This webpage has a redirect loop
The webpage at http://example.com/ has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.
Here are some suggestions:
Reload this webpage later.
Learn more about this problem.
Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.
 
Old 04-19-2013, 04:07 PM   #9
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,171

Rep: Reputation: 752Reputation: 752Reputation: 752Reputation: 752Reputation: 752Reputation: 752Reputation: 752
Check very carefully that you don't have www.yourdomain.com in the list of ServerAliases

The example I've given does work, I use it (with a lot more domain names) on my production server.
 
Old 04-19-2013, 08:16 PM   #10
SernOne
Member
 
Registered: Oct 2012
Posts: 33

Original Poster
Rep: Reputation: Disabled
Here is what i have
Code:
<VirtualHost *:80>
    ServerAdmin staff@example.com
    DocumentRoot /home/example/public_html
    ServerName www.example.com
    ServerAlias example.com
    ServerAlias www.example.co
    ServerAlias www.example.info
    ServerAlias www.example.net
    ServerAlias www.example.org
    ServerAlias example.co
    ServerAlias example.info
    ServerAlias example.net
    ServerAlias example.org

    RedirectMatch 301 (.*) http://www.example.com$1
    ErrorLog logs/example-error_log
    CustomLog logs/example-access_log common
</VirtualHost>
 
Old 04-20-2013, 01:27 AM   #11
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,171

Rep: Reputation: 752Reputation: 752Reputation: 752Reputation: 752Reputation: 752Reputation: 752Reputation: 752
Quote:
Originally Posted by SernOne View Post
Here is what i have
The domains you want to redirect and your Redirect match need to be in a different vhost container:

Code:
<VirtualHost *:80>
    ServerAdmin staff@example.com
    DocumentRoot /home/example/public_html
    ServerName www.example.com
    ServerAlias example.com
    ErrorLog logs/example-error_log
    CustomLog logs/example-access_log common
</VirtualHost>

<VirtualHost *:80>
    ServerName www.example.co
    ServerAlias www.example.info
    ServerAlias www.example.net
    ServerAlias www.example.org
    ServerAlias example.co
    ServerAlias example.info
    ServerAlias example.net
    ServerAlias example.org

    RedirectMatch 301 (.*) http://www.example.com$1
</VirtualHost>
Having them all in the one vhost container means every request is being re-written, INCLUDING the ones to www.example.com, that's causing your looping.

You could also take ServerAlias example.com out and put it in the redirect container too.

Last edited by TenTenths; 04-20-2013 at 01:30 AM.
 
1 members found this post helpful.
Old 04-23-2013, 11:59 PM   #12
SernOne
Member
 
Registered: Oct 2012
Posts: 33

Original Poster
Rep: Reputation: Disabled
Perfection thank you for the help worked like a charm!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Multiple emails accounts(with different from domains) on multiple domains on 1 server locoputo Linux - Server 0 04-12-2009 07:29 PM
Multiple domains in LDAP and 1 samba server for all domains, what to do? xnomad Linux - Server 1 11-14-2008 10:12 AM
Installing ftp,mail forwarding and domains on cent os 5 centosfan Linux - Server 0 01-04-2008 08:05 AM
Sub Domains & Multiple Domains (Apache) lugos Linux - Server 1 09-01-2006 11:22 PM
Forwarding domains rather than ports? cquinn Linux - Newbie 2 03-31-2004 11:43 AM


All times are GMT -5. The time now is 08:42 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration