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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
04-16-2006, 09:20 PM
|
#1
|
LQ Newbie
Registered: Apr 2006
Posts: 8
Rep:
|
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 09:23 PM.
|
|
|
04-16-2006, 09:48 PM
|
#2
|
Member
Registered: Mar 2006
Posts: 110
Rep:
|
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.
|
|
|
04-17-2006, 12:28 AM
|
#3
|
LQ Newbie
Registered: Apr 2006
Posts: 8
Original Poster
Rep:
|
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-17-2006 at 12:50 AM.
|
|
|
04-17-2006, 01:24 AM
|
#4
|
Member
Registered: Mar 2006
Posts: 110
Rep:
|
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.
|
|
|
04-17-2006, 01:48 AM
|
#5
|
LQ Newbie
Registered: Apr 2006
Posts: 8
Original Poster
Rep:
|
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!
|
|
|
04-17-2006, 01:50 AM
|
#6
|
LQ Newbie
Registered: Apr 2006
Posts: 8
Original Poster
Rep:
|
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 01:56 AM.
|
|
|
04-17-2006, 01:55 AM
|
#7
|
LQ Newbie
Registered: Apr 2006
Posts: 8
Original Poster
Rep:
|
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!
|
|
|
04-17-2006, 02:16 AM
|
#8
|
Member
Registered: Mar 2006
Posts: 110
Rep:
|
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.
|
|
|
04-18-2006, 01:57 AM
|
#9
|
LQ Newbie
Registered: Apr 2006
Posts: 8
Original Poster
Rep:
|
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.
|
|
|
04-18-2006, 04:56 AM
|
#10
|
Member
Registered: Mar 2006
Posts: 110
Rep:
|
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.
|
|
|
04-19-2006, 02:38 AM
|
#11
|
LQ Newbie
Registered: Apr 2006
Posts: 8
Original Poster
Rep:
|
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!
|
|
|
All times are GMT -5. The time now is 12:06 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|