logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in  RSS Apache Lounge  


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.



Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: redirect from port 80 to port 8443 only on one server
Author
rootnk



Joined: 29 Oct 2019
Posts: 3
Location: Canada,Edmonton

PostPosted: Tue 29 Oct '19 18:13    Post subject: redirect from port 80 to port 8443 only on one server Reply with quote

How do I redirect ONLY my principle server from port 80 to port 8443?

I have tried
Code:

RewriteEngine On

RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]

RewriteCond %{HTTP_HOST} !^www.nk.ca$ [NC]
RewriteRule ^(.*)$ https://www.nk.ca:8443/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^www.nk.ca$ [NC]
RewriteRule ^/?$ "https\:\/\/www\.nk\.ca\:8443\/" [L,R=301]

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}:8443%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://www.nk.ca:8443/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{SERVER_PORT} ^80$
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI}:8443 [R=301,L]

RewriteCond %{HTTP_HOST} !^secure.nl2k.ab.ca$ [NC]
RewriteRule ^(.*)$ https://secure.nl2k.ab.ca/$1 [L,R=301]

RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* - [F,L]

RewriteCond %{SERVER_PORT} !^8443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}:8443/%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} ^204\.209\.81\.1
RewriteRule ^(.*) https://www.nk.ca:8443/$1 [R=301.L]


RewriteRule    ^blog/(.*)$    https://www.nk.ca:8443/blog/$1    [R=301,NC,L]

and no luck. Pointers please.
Back to top
mraddi



Joined: 27 Jun 2016
Posts: 100
Location: Schömberg, Baden-Württemberg, Germany

PostPosted: Wed 30 Oct '19 8:18    Post subject: Reply with quote

Hello,

I had success with these lines for redirecting only http-requests to servera.example.com to https. Requests to serverb.example.com are nont redirected.
Code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} =servera.example.com [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=302,L]

Best regards
Matthias
Back to top
rootnk



Joined: 29 Oct 2019
Posts: 3
Location: Canada,Edmonton

PostPosted: Thu 31 Oct '19 13:29    Post subject: Reply with quote

problem is that this goes to port 443. I wish to redirect to port 8443
Back to top
mraddi



Joined: 27 Jun 2016
Posts: 100
Location: Schömberg, Baden-Württemberg, Germany

PostPosted: Thu 31 Oct '19 14:08    Post subject: Reply with quote

Feel free to use the muscle between you ears (aka "brain" Wink) and add the port :8443 at the correct position:
Code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} =servera.example.com [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}:8443/$1 [R=302,L]


Greetings to beautiful Canada Very Happy
Back to top
rootnk



Joined: 29 Oct 2019
Posts: 3
Location: Canada,Edmonton

PostPosted: Thu 07 Nov '19 4:44    Post subject: Reply with quote

mraddi

Yes

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} =servera.example.com [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}:8443/$1 [R=302,L]

but still what to redirect to port 443 initially instead of 8443
Back to top
mraddi



Joined: 27 Jun 2016
Posts: 100
Location: Schömberg, Baden-Württemberg, Germany

PostPosted: Thu 07 Nov '19 13:40    Post subject: Reply with quote

I hope you have already deleted the not-working rules from your configuration as some of them are wrong or at least superfluous.

Please ensure that there are no other rewrite-rules redirecting to :443 that are used before this new rule.
In addition I had the effect that 301-redirects where cached by a browser and therefore modifying a rewrite-rule didn't have the desired result as the browser used its cached data (in this case the redirect to :443 instead of :8443). So clearing the browser's cache might be a good idea.

Just an additional question: why do you want to redirect to https://...:8443 instead only to https://...:443 and use Apache's reverse-proxy-functionality? Of course I can imagine some reasons but sometimes this approach is more transparent for users and is working, too Smile.
Back to top


Reply to topic   Topic: redirect from port 80 to port 8443 only on one server View previous topic :: View next topic
Post new topic   Forum Index -> Apache