LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Forwarding mutlitable domains (https://www.linuxquestions.org/questions/linux-newbie-8/forwarding-mutlitable-domains-4175458555/)

SernOne 04-17-2013 10:14 PM

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

bathory 04-18-2013 01:49 AM

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

SernOne 04-18-2013 02:20 PM

Yes I have done that however i was looking for if someone goes to example.co it will forward to example.com instead.

bathory 04-18-2013 03:14 PM

Quote:

Originally Posted by SernOne (Post 4934238)
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]


SernOne 04-18-2013 07:36 PM

Quote:

Originally Posted by bathory (Post 4934276)
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.

bathory 04-19-2013 02:27 AM

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).

TenTenths 04-19-2013 03:57 AM

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.

SernOne 04-19-2013 02:32 PM

Quote:

Originally Posted by TenTenths (Post 4934616)
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.

TenTenths 04-19-2013 03:07 PM

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.

SernOne 04-19-2013 07:16 PM

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>


TenTenths 04-20-2013 12:27 AM

Quote:

Originally Posted by SernOne (Post 4934998)
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.

SernOne 04-23-2013 10:59 PM

Perfection thank you for the help worked like a charm!


All times are GMT -5. The time now is 07:13 AM.