LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 04-16-2006, 08:20 PM   #1
thunder04
LQ Newbie
 
Registered: Apr 2006
Posts: 8

Rep: Reputation: 0
Question 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!!

Last edited by thunder04; 04-16-2006 at 08:23 PM.
 
Old 04-16-2006, 08:48 PM   #2
rahulk
Member
 
Registered: Mar 2006
Posts: 110

Rep: Reputation: 16
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.
 
Old 04-16-2006, 11:28 PM   #3
thunder04
LQ Newbie
 
Registered: Apr 2006
Posts: 8

Original Poster
Rep: Reputation: 0
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!

Last edited by thunder04; 04-16-2006 at 11:50 PM.
 
Old 04-17-2006, 12:24 AM   #4
rahulk
Member
 
Registered: Mar 2006
Posts: 110

Rep: Reputation: 16
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.
 
Old 04-17-2006, 12:48 AM   #5
thunder04
LQ Newbie
 
Registered: Apr 2006
Posts: 8

Original Poster
Rep: Reputation: 0
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!
 
Old 04-17-2006, 12:50 AM   #6
thunder04
LQ Newbie
 
Registered: Apr 2006
Posts: 8

Original Poster
Rep: Reputation: 0
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)

Last edited by thunder04; 04-17-2006 at 12:56 AM.
 
Old 04-17-2006, 12:55 AM   #7
thunder04
LQ Newbie
 
Registered: Apr 2006
Posts: 8

Original Poster
Rep: Reputation: 0
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!
 
Old 04-17-2006, 01:16 AM   #8
rahulk
Member
 
Registered: Mar 2006
Posts: 110

Rep: Reputation: 16
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.
 
Old 04-18-2006, 12:57 AM   #9
thunder04
LQ Newbie
 
Registered: Apr 2006
Posts: 8

Original Poster
Rep: Reputation: 0
Thumbs up

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.
 
Old 04-18-2006, 03:56 AM   #10
rahulk
Member
 
Registered: Mar 2006
Posts: 110

Rep: Reputation: 16
Post

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 .

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.
 
Old 04-19-2006, 01:38 AM   #11
thunder04
LQ Newbie
 
Registered: Apr 2006
Posts: 8

Original Poster
Rep: Reputation: 0
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!
 
  


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
need a mail relay that rewrite the sender's domain linuxboy123 Linux - Networking 3 04-20-2005 03:42 PM
Need help with Apache rewrite rules?? latino Programming 0 12-24-2004 02:09 AM
apache mod rewrite Robert0380 Linux - Software 5 07-31-2003 04:42 PM
Apache rewrite question CrazyToon Linux - Software 3 06-17-2003 02:00 PM
Apache Rewrite Not Working mikeyt_333 Linux - General 1 05-20-2003 05:00 PM


All times are GMT -5. The time now is 02:47 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration