LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Apache 2 Rewrite One Domain To Another (https://www.linuxquestions.org/questions/linux-software-2/apache-2-rewrite-one-domain-to-another-435793/)

thunder04 04-16-2006 08:20 PM

Apache 2 Rewrite One Domain To Another
 
I recently purchased a domain (mn12.us). I then decided to purchase (themn12.com). How do I configure Apache 2 (running on a Debian server) to redirect users from 'mn12.us', 'www.mn12.us' and 'themn12.com' to 'www.themn12.com'?

FYI: I have never messed with the mod_rewrite before.

Thanks!!

rahulk 04-16-2006 08:48 PM

Quote:

Originally Posted by thunder04
I recently purchased a domain (mn12.us). I then decided to purchase (themn12.com). How do I configure Apache 2 (running on a Debian server) to redirect users from 'mn12.us', 'www.mn12.us' and 'themn12.com' to 'www.themn12.com'?

FYI: I have never messed with the mod_rewrite before.

Thanks!!

You can put the following entry in the virtualhost of mn12.us box's apache config file.


<VirtualHost *>
ServerName mn12.us
****
**
DocumentRoot **
RewriteEngine on
RedirectMatch permanent ^/$ http://www.themn12.com

</VirtualHost>

However, I fail to understand why do you want to redirect from themn12.com to www.themn12.com. you can simply change the ServerName of themn12.com to www.themn12.com.

-Rahul.

thunder04 04-16-2006 11:28 PM

Is there another way to configure apache to when a user browses to 'themn12.com' that it'll automatically redirect them to 'www.themn12.com'??

I'm just picky on how my domain looks in the web browser and want to force everybody to view the website at 'www.themn12.com', but don't want it to display an error when they browse to 'themn12.com'

Also, I edit my apache config as per your instructions (by adding the RewriteEngine and RedirectMatch lines to a VirtualHost entry for mn12.us) and it did not work. I got the error "Invalid command 'RewriteEngine', perhaps mis-spelled or defined by a module not included in the server configuration"

This is how I have my VirtualHost entry set-up for the domains:

<VirtualHost *:80>
ServerName www.themn12.com
ServerAlias themn12.com www.themn12.com mn12.us www.mn12.us
DocumentRoot /home/anthony/mn12us
ServerAdmin [my e-mail address]
</VirtualHost>

How do I re-configure to redirect 'mn12.us', 'www.mn12.us', and 'themn12.com' to 'www.themn12.com'?

Thanks!

rahulk 04-17-2006 12:24 AM

Quote:

Originally Posted by thunder04
Is there another way to configure apache to when a user browses to 'themn12.com' that it'll automatically redirect them to 'www.themn12.com'??

I'm just picky on how my domain looks in the web browser and want to force everybody to view the website at 'www.themn12.com', but don't want it to display an error when they browse to 'themn12.com'

Also, I edit my apache config as per your instructions (by adding the RewriteEngine and RedirectMatch lines to a VirtualHost entry for mn12.us) and it did not work. I got the error "Invalid command 'RewriteEngine', perhaps mis-spelled or defined by a module not included in the server configuration"

This is how I have my VirtualHost entry set-up for the domains:

<VirtualHost *:80>
ServerName www.themn12.com
ServerAlias themn12.com www.themn12.com mn12.us www.mn12.us
DocumentRoot /home/anthony/mn12us
ServerAdmin [my e-mail address]
</VirtualHost>

How do I re-configure to redirect 'mn12.us', 'www.mn12.us', and 'themn12.com' to 'www.themn12.com'?

Thanks!


ServerAlias allows you to do that, since the settings are already in place, can you paste me the contents of /etc/hosts file ??
If there is a entry for www.themn12.com, then you can add themn12.com in it.

Seems like the DNS entry is not present for aliases.

In case RewriteEngine is not working check for mod_rewrite.c module, it might be missing. no problem, for Redirect to work you need mod_alias module to be there in apache. I believe it should be there. make the changes as

<VirtualHost *:80>
ServerName mn12.us
****
**
DocumentRoot **
RedirectMatch permanent ^/$ http://www.themn12.com

</VirtualHost>

hope it works, paste me the contents of /etc/hosts file.

-Rahul.

thunder04 04-17-2006 12:48 AM

This is what is in my /etc/hosts file:

----
127.0.0.1 localhost.localdomain localhost
10.0.1.2 debsrv02.hhsn.net debsrv02

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
----

I will give what you said a try. Thanks for your help!

thunder04 04-17-2006 12:50 AM

Quote:

Originally Posted by rahulk
<VirtualHost *:80>
ServerName mn12.us
****
**
DocumentRoot **
RedirectMatch permanent ^/$ http://www.themn12.com

</VirtualHost>

I kind-of feel like an idiot for asking...but...what do the wildcards mean between ServerName and DocumentRoot??

NEVERMIND! (don't know how to delete this post)

thunder04 04-17-2006 12:55 AM

Awesome! The simple redirect works!

Now to throw in a twist. This will probably require mod_rewrite...and I had just thought about it.

How do I configure it to redirect http://mydomains.com/stuff to http://www.themn12.com/stuff ?

This is because if somebody has "http://www.mn12.us/thing" linked, I wouldn't want the link to become broken, but to re-direct to "http://www.themn12.com/thing", if you know what I mean?

Again, many thanks!

rahulk 04-17-2006 01:16 AM

Quote:

Originally Posted by thunder04
Awesome! The simple redirect works!

Now to throw in a twist. This will probably require mod_rewrite...and I had just thought about it.

How do I configure it to redirect http://mydomains.com/stuff to http://www.themn12.com/stuff ?

This is because if somebody has "http://www.mn12.us/thing" linked, I wouldn't want the link to become broken, but to re-direct to "http://www.themn12.com/thing", if you know what I mean?

Again, many thanks!

ofcourse I understand, see the rewrite rules are for internal redirection but since you wanna have a complete shift over from one domain to other you have many options, you can use

Redirect /thing http://www.themn12.com/thing

or

RedirectMatch ^/thing(.*)$ http://www.themn12.com/thing$1 [R]

What I suppose is that /thing should be a application with context name as thing. If you wanna have all the static pages and everything to be redirected, you may try

RedirectMatch ^/(.*)$ http://www.themn12.com/$1 [R]

let me know if this is success.

-Rahul.

thunder04 04-18-2006 12:57 AM

Works great! You are the master!

Now, for one last question...lol...

I don't have any use for this as of now...but I am curious (for my own knowledge)...

Let's say I have 'http://foo.com/bar/*'. How would I set up a redirect to redirect from 'http://foo.com/bar/*' to 'http://bar.foo.com/*'? I guess a practical application may be for redirecting users from a hypothetical 'http://www.themn12.com/forums/*' to 'http://forums.themn12.com/'*

Again, many thanks.

rahulk 04-18-2006 03:56 AM

Quote:

Originally Posted by thunder04
Works great! You are the master!

Now, for one last question...lol...

I don't have any use for this as of now...but I am curious (for my own knowledge)...

Let's say I have 'http://foo.com/bar/*'. How would I set up a redirect to redirect from 'http://foo.com/bar/*' to 'http://bar.foo.com/*'? I guess a practical application may be for redirecting users from a hypothetical 'http://www.themn12.com/forums/*' to 'http://forums.themn12.com/'*

Again, many thanks.

sounds good that your problem is solved. stating in simple words, m not a master :) the study goes on :study:.

tht is a nice question, see for 'http://forums.themn12.com/*' to happen, you can make use of following ideas.For application to be loaded from http://www.themn12.com/forums to http://forums.themn12.com/

1. define Virtualhost within themn box and "redirect match" any request starting with ^/forums to http://forums.themn12.com , as your virtual host registers this URL, there will be no problem.

2. You may make use of virtual hosting also to define IP address based virtual hosts which shall be listening on different IP addresses within themn12 box. this can be done by creating dummy interface.

3. Build up a local LAN for individual servers having instances of http running on them for different applications like forum. Name these individual servers the "ServerName forums.themn12.com" as well as put the entry of these servers in the hosts file of the main webserver, i.e themn12 box. remember, this LAN must be an internal one and keep the traffic from internet to passthrough themn12 box otherwise you might create a security issue. this allows you to redirect the huge traffic on individual machines rather then on a single themn12 box.

Generally speaking the best choice would be

to go for first, if traffic is little and you want it to be robust.

to go for second, if you need to have many different domains established (however, you can use many instances of http on a single server also for this.)

to go for third, if there is large performance issue, specially on a Production server.

do remember that you will have to add entry of the host in /etc/hosts otherwise this would fail badly as DNS lookup will never be able to figure out the one way traffic.

-Rahul.

thunder04 04-19-2006 01:38 AM

Awesome! Everything works exactly how I want. It utterly amazes me how much I've learned over the years...and how much I keep learning!!

Thank you, very much! :D


All times are GMT -5. The time now is 11:18 PM.