Solved

Apache virtual host redirection to URL

Posted on 2010-08-16
6
526 Views
Last Modified: 2013-11-30
Hi,

I need to redirect a domain to a specific file on my server and are not sure how.

I have 2 domains one had several files on that I like to have another domain link to.

e.g I have www.domain1.com/myfile.html

I like to configure domain to to link direct to this html page. I can not make it a directory which is the issue here it need to be the HTML page. Is there a way to configure the vhost of the second domain to link direct to this url of domain 1?


I did try the one below but it does not work

<VirtualHost xxx.xxx.xxx.xxx:80>
DocumentRoot /home/domain2/htdocs
ServerName domain2.com
ServerAdmin info@domain2.com
ServerAlias www.domain2.com
CustomLog /home/domain2/logs/access_log "special"
<Directory "/home/domain2/htdocs">
Options FollowSymLinks Includes IncludesNOEXEC
</Directory>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} !^(GET|POST|HEAD)$
RewriteRule $ http://www.domain1.my/myfilehtml [L]
</IfModule>
</VirtualHost>


Any help is appreciated.

Best wishes,
Thom
0
Comment
Question by:Thomanji
6 Comments
 
LVL 11

Expert Comment

by:Pieter Jordaan
ID: 33445730

Remove the domain2 vhost, and just add
ServerAlias www.domain2.com

to the vhost of domain1
0
 
LVL 6

Expert Comment

by:Joshua1909
ID: 33445740
Hi Thom,
Can you let me know a bit more about what you're trying to achieve? There a a few ways you can do this, but it would help to know more.
The first thing that comes to mind is that you can modify apache to look for your 'myfile.html' page in your web directory as the default page to load rather than index.html or whatever.


*Edit the files httpd.conf and srm.conf file and do the following:
Find this line.
DirectoryIndex index.html
and change it as follows:

DirectoryIndex index.shtml index.html

Of course, you can use any filename you wish.

*source: http://bignosebird.com/apache/a2.shtml

Cheers,
Josh
0
 
LVL 11

Expert Comment

by:Pieter Jordaan
ID: 33445761
Another way would be to just redirect domain2 to domain1 using an index.php file with the following contents:

<?php
header ('Location: http://www.domain1.com');
?>

I hope that helps.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:Thomanji
ID: 33451112
Hi Guys,

I thank you for the feedback which is probably what i will do if I do not find anything else.

Let me explain a bit more what exactly i do.

I have a content management system that does not work with directory. So each page is something like domain1.com/some_page.html
The site in question is a home-improvement site.

lets say I have:
domain1.com/aircondition.html

and I have a second domain called
air-condition.com

now I want that when someone goes to air-condition.com he comes out on domain1.com/aircondition.html

of course I can do a php redirect like suggested by BitFreeze but I wondered if there is a way to do it from the httpd.conf file in apache.

I will try Joshua idea because I could just make aircondition.html the default page on the second domain.

Best wishes,
Thom
0
 
LVL 26

Accepted Solution

by:
arober11 earned 500 total points
ID: 33525819
If you want to keep your two separate virtual hosts, just remove the following line and re-start Apache:

RewriteCond %{REQUEST_METHOD} !^(GET|POST|HEAD)$
0
 

Author Closing Comment

by:Thomanji
ID: 33530180
Hi,

arober11 that did it, simple and works fine.

Thank you all for the help.

Best wishes,
Thom
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Network connections wi-fi configuration issue 6 30
Cisco switch suggestion 5 49
Help logging in to my router 12 48
Wireless scope on sever with DSL connection 9 23
Don’t let your business fall victim to the coming apocalypse – use our Survival Guide for the Fax Apocalypse to identify the risks and signs of zombie fax activities at your business.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question