[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 541
  • Last Modified:

Apache virtual host redirection to URL

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
Thomanji
Asked:
Thomanji
1 Solution
 
Pieter JordaanCommented:

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

to the vhost of domain1
0
 
Joshua1909Commented:
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
 
Pieter JordaanCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ThomanjiAuthor Commented:
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
 
arober11Commented:
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
 
ThomanjiAuthor Commented:
Hi,

arober11 that did it, simple and works fine.

Thank you all for the help.

Best wishes,
Thom
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now