LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Apache HTTP to HTTPS Redirection on Non-Standard Port!!! (https://www.linuxquestions.org/questions/linux-server-73/apache-http-to-https-redirection-on-non-standard-port-4175478846/)

raheel_com88 09-28-2013 02:06 AM

Apache HTTP to HTTPS Redirection on Non-Standard Port!!!
 
Dear Members,

I want to achieve HTTP to HTTPs Redirection on Non-Standard Port using Apache. I have a URL http://mail.mydomain.com:9000/ which I want redirect to https://mail.mydomain.com:9000/.

I am currently using it in Apache using

Redirect http://mail.mydomain.com:9000/ https://mail.mydomain.com:9000/

but it's not working at all. Can anyone help?

bathory 09-28-2013 03:02 AM

Quote:

Originally Posted by raheel_com88 (Post 5036260)
Dear Members,

I want to achieve HTTP to HTTPs Redirection on Non-Standard Port using Apache. I have a URL http://mail.mydomain.com:9000/ which I want redirect to https://mail.mydomain.com:9000/.

I am currently using it in Apache using

Redirect http://mail.mydomain.com:9000/ https://mail.mydomain.com:9000/

but it's not working at all. Can anyone help?

You don't give more detail about your setup, but in any case you should use the following Redirect in the HTTP vhost:
Code:

Redirect / https://mail.mydomain.com:9000/
Regards

raheel_com88 09-28-2013 08:16 AM

Finally I am able to configure it with two listeners. I configure the apache to listen on two ports "Listen 80" and "Listen 9000" and Redirect it one using simple "Redirect / https://mail.mydomain.com:9001/" and other in virtual host <VirtualHost *:80> Redirect / https://mail.mydomain.com/ </VirtualHost>

But it's an IP based redirection. Now I want to achieve hostname based Redirection. I am running a mail server and have different domains hosted on it. I want every http://hostname which resolve to my IP to https://hostname. Anyone who can help me with that?

raheel_com88 09-28-2013 09:13 AM

Quote:

Originally Posted by raheel_com88 (Post 5036390)
Finally I am able to configure it with two listeners. I configure the apache to listen on two ports "Listen 80" and "Listen 9000" and Redirect it one using simple "Redirect / https://mail.mydomain.com:9001/" and other in virtual host <VirtualHost *:80> Redirect / https://mail.mydomain.com/ </VirtualHost>

But it's an IP based redirection. Now I want to achieve hostname based Redirection. I am running a mail server and have different domains hosted on it. I want every http://hostname which resolve to my IP to https://hostname. Anyone who can help me with that?

Frankly speaking I want when user browse "http://mail.<his_domain>.tld" he will be redirected to "https://mail.<his_domain>.tld". One way we can do this is by Defining a VirtualHost for each domain something like that:

<VirtualHost 192.168.1.1:80>
ServerName mail.boogyman.com
Redirect / https://mail.boogymain.com
</VirtualHost>

<VirtualHost 192.168.1.1:80>
ServerName mail.thunderbird.com
Redirect / https://mail.thunderbird.com
</VirtualHost>

But I need a more generic way because I have 100 of domains hosted at Mail Server. Any possible way?

bathory 09-28-2013 09:52 AM

But I need a more generic way because I have 100 of domains hosted at Mail Server. Any possible way?
Then you should use mod_rewrite:
Code:

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

Regards

raheel_com88 09-28-2013 10:32 AM

Quote:

Originally Posted by bathory (Post 5036423)
But I need a more generic way because I have 100 of domains hosted at Mail Server. Any possible way?
Then you should use mod_rewrite:
Code:

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

Regards

OK Thanks.But how to redirect http://mail.<domain>.tld:9000/ to https://mail.<domain>.tld:9443 using mod_rewrite.

bathory 09-28-2013 11:59 AM

Quote:

Originally Posted by raheel_com88 (Post 5036435)
OK Thanks.But how to redirect http://mail.<domain>.tld:9000/ to https://mail.<domain>.tld:9443 using mod_rewrite.

Add another condition like:
Code:

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{SERVER_PORT} ^9000$
RewriteRule ^(.*)$ https://%{HTTP_HOST}:9443%{REQUEST_URI}


raheel_com88 11-13-2013 12:31 AM

Dear,

Now I face another issue. I installed awstats and now Webserver is listening on port 8000. I want to redirect http://<ip>:8000/awstats to http://<ip>:8000/awstats/awstats.pl?config=mywebsite.com. I am doing it using Redirect but it isn't working at all? Any suggestions.

bathory 11-13-2013 03:49 AM

Quote:

Originally Posted by raheel_com88 (Post 5063521)
Dear,

Now I face another issue. I installed awstats and now Webserver is listening on port 8000. I want to redirect http://<ip>:8000/awstats to http://<ip>:8000/awstats/awstats.pl?config=mywebsite.com. I am doing it using Redirect but it isn't working at all? Any suggestions.

Try this:
Code:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/awstats/awstats.pl
RewriteRule ^(.*)awstats /awstats/awstats.pl?config=mywebsite.com



All times are GMT -5. The time now is 06:51 AM.