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!! |
Quote:
<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. |
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! |
Quote:
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. |
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! |
Quote:
NEVERMIND! (don't know how to delete this post) |
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! |
Quote:
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. |
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. |
Quote:
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. |
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. |