Redirection???

Support for webhosts that use CentOS
Post Reply
borispauck
Posts: 2
Joined: 2011/08/16 10:15:22

Redirection???

Post by borispauck » 2011/08/16 10:27:32

Hello !

I am new there and if someone should help me a little bit I'll be very appreciative.

However, I am using CentOS 5.6 for hosting my site and I want to create a redirection.

For example, if user types http://www.example.com/mail into Web browser, it automatically redirects him to
https://web1.example.com, where is an e-mail application.

I've been trying with creating folder mail in root with .htaccess file and editing it, but it didn't work.


Thanks in advance!


-Boris

hawaiian717
Posts: 178
Joined: 2009/01/30 19:58:25
Location: California

Re: Redirection???

Post by hawaiian717 » 2011/08/16 15:51:55

It may not be the most elegant way, but I usually do it with a PHP script.

In the webroot for www.example.com, create a directory mail, and in that directory, create a file named "index.php". In that file, add the following:

[code]<?php header('Location: https://web1.example.com/'); ?>[/code]

logan
Posts: 64
Joined: 2008/08/01 16:40:34

Redirection???

Post by logan » 2011/08/16 18:05:53

You probably need to enable .htaccess files in the web sever/vhost config:

[code]<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/example.com
<Directory /var/www/example.com>
AllowOverride All
</Directory>
</VirtualHost>[/code]

Or just throw the redirect right in the vhost:

[code]<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
RedirectMatch ^/mail https://web1.example.com
DocumentRoot /var/www/example.com
</VirtualHost>[/code]

The PHP thing will get the job done as well so long as you've got PHP installed. I prefer using Apache directives if possible and grouping them all in the same place (vhost if no DocumentRoot or the main .htaccess) so I can see the list right there and not have to search through dozens of directories trying to find them all.

borispauck
Posts: 2
Joined: 2011/08/16 10:15:22

Re: Redirection???

Post by borispauck » 2011/08/17 07:08:10

Thanks for quick and detailed answers.

Php script works. I've been also reading about VHosts, and I've found something explained for applications and sites hosted on the same web server.

Problem is there that my Web application is on the one server (virtual machine CentOS 5.6) with one IP address, and web site is on the another server (virtual machine, CentOS 5.6) with other IP address. Can VHosts be used in that way for redirection?

Thanks!

-Boris

Post Reply

Return to “CentOS 5 - Webhosting Support”