LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Page redirect in Apache with mod_rewrite (http://www.linuxquestions.org/questions/linux-newbie-8/page-redirect-in-apache-with-mod_rewrite-936070/)

moyorakkhi 03-23-2012 12:55 PM

Page redirect in Apache with mod_rewrite
 
Hello,

In our mail server there are multiple virtual email domain hosted. User can use webmail.example.com (this is the first apache virtualhost) to check mail or they can use mail.THEIR-DOMAIN.com. If the put mail.THEIR-DOMAIN.com apache shows the webmail.example.com as it is the first virtualhost and mail.THEIR-DOMAIN.com doesn't exist. Recently we imposed https for webmail.example.com and added this mod_rewrite rule:
Code:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

But now users not getting the default webmail page as they were getting before. How can we redirect all request coming to the URL "mail.ANY-DOMAIN.com" to "https://webmail.example.com"? I've tried the following but it didn't work:

Code:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (mail.*) https://webmail.example.com


Sydney 03-23-2012 02:17 PM

# Add the rule
RewriteCond %{HTTPS} on
RewriteRule (mail.*) https://webmail.example.com

moyorakkhi 03-23-2012 03:13 PM

Hi Sydney,

Thanks for your response. It's not working actually. I've tried adding it on both webmail.example.com virtualhost entry as well as in httpd.com file. Traffic not redirecting to https://webmail.example.com.

Thanks again!

Sydney 03-23-2012 03:16 PM

I hope not to send you on a goose chase but I always have on in lower case.

moyorakkhi 03-23-2012 03:49 PM

Yeah. I also have "on" in lower case. But it's not happening.

Sydney 03-23-2012 04:28 PM

RewriteEngine on

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(mail.*)$ https://webmail.example.com [R]

moyorakkhi 03-23-2012 05:07 PM

Thanks for your help Sydney. I Got it working with the following:

Code:

<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mail. [NC]
RewriteRule ^(.*)$ https://webmail.example.com/$1 [L,R=301]
</VirtualHost>

I tried with your code as well. But didn't worked unfortunately.

Sydney 03-23-2012 05:11 PM

Quote:

Originally Posted by moyorakkhi (Post 4634745)
Code:

<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mail. [NC]
RewriteRule ^(.*)$ https://webmail.example.com/$1 [L,R=301]
</VirtualHost>


I am glad you got it resolved! Thanks for posting your solution.


All times are GMT -5. The time now is 08:51 PM.