Page 1 of 1

Redirection???

Posted: 2011/08/16 10:27:32
by borispauck
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

Re: Redirection???

Posted: 2011/08/16 15:51:55
by hawaiian717
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]

Redirection???

Posted: 2011/08/16 18:05:53
by logan
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.

Re: Redirection???

Posted: 2011/08/17 07:08:10
by borispauck
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