In terms of redirecting visitors, by not including
RewriteCond %{SERVER_PORT} 80
will I skip over any potential visitors? Or is port 80 the default?
Port 80 is the default for HTTP, 443 for HTTPS.
Related
i have a service that is running over docker under port 8081 ( on ubuntu 20 ) and i can access it under http:
my-domain.local:8081/myservice
i have installed apache2 as a reverse proxy in front of it and it works also fine and i can access the service under https (443) and my ssl certificates:
https://my-domain.local/myservice --- works fine
but its still accessible under http also and i dont want it. I want that it will be accessible only under https:
http://my-domain.local:8081/myservice ----> https://my-domain.local/myservice
it is maybe a very simple situation but i am new to apache. Thanks for your help
That is what i have tried:
<VirtualHost *:8081>
ServerName my-domain.local
Redirect "/" "https://my-domain.local/myservice"
</VirtualHost>
i have also tried something with the use of RewriteRule in the .htacces like below:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
but none of the works.
i expect, if someone calls the url under http in browser it will be redirected to https:
http://my-domain.local:8081/myservice ----> https://my-domain.local/myservice
I got 2 domains "abc.com" and "def.com". On ports 443 and 3001 I got React apps. Both domains go to same server.
I would like htaccess to run react app from port 3001 ( without showing port number ) when user try to access "def.com" and open deafult 443 port when user try to access "abc.com" ( simulate that both domains run on 443 )
After messing with .htaccess, I managed to get this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^abc\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}:3001
RewriteCond %{HTTP_HOST} ^def\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}
Second site run on default ports ( 80 and 443 ) where first run on 3001. Is there any "easy" way to hide port in url other than messing with javascript on each request?
In my perfect world, both would run on 443 and .htaccess would manage domains but since I don't know any better way for that, thats how I did it.
You can use port-based virtual hosting using Apache Web Server. There could be other ways too, but you can give it a try.
There could be multiple steps to follow, but they are quite easy and simple. I'm not sure which OS or hosting environment you are using though you should check this.
Got a vServer and plesk installed on it (Apache backend, Nginx reverse proxy), plesk is listening on port 8443.
I use the hostname as a domain for easier accesss and SSL certificate domain. So I would like to redirect ALL traffic to specific one:
What I got so far is this rule
return 301 https://www.DOMAIN.com:8443/;
which leads everything to the Plesk Panel URL but if someone is using this
https://DOMAIN.com:8443
he won't be redirected to
https://www.DOMAIN.com:8443
and the SSL certificate won't work (domain based). How can I force every traffic (http and https with the ports 80 and 8443) to
https://www.DOMAIN.com:8443
Thanks in advance
You could HTACCESS to do it:
The Code
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI}:8443 [R=301,L]
What this does is check if the user is trying to access the site without using www and if so redirect to www on the specific port that you wanted.
If you already have your port 80 traffic redirecting to port 8443 and you just want to redirect the rule for www, what I have listed above will work. You can also have mod rewrite redirect based on the port used.
It would look like this:
The Code
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{SERVER_PORT} ^80$
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI}:8443 [R=301,L]
You would just need to make sure that each virtual host you are using has the mod rewrite rule in place. You might have to create a virtual host for the extra ports you want to use. The only thing these virtual hosts would have is the redirect rule. Otherwise you might get 404 errors.
I'm working on a website locally that contains https links, so when I click on one of these links it takes me to https://localhost/... which doesn't exist as there is no SSL certificate installed.
Is there anything I can add to .htaccess that checks if I'm on localhost and if so redirects https to http? The .htaccess file is used in both local development and production on our server so anything I add mustn't affect the live website.
Nope.
Reason is any rules you put in your htaccess file will only get applied once the request has been made, which means it'll only get applied once the https://localhost/ request is made. If there's nothing listening to the HTTPS port (443) on localhost, then the rules will never get applied.
If port 443 is listening for requests on localhost, but it's just a matter of lacking an SSL certificate, the rules still won't get applied until after the SSL handshake is performed, which means, you're still going to get the security warning about your certificate.
That being said, the rules you'd want if you had apache listening to port 443 and have a certificate installed is this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^localhost$ [NC]
RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R]
I have a few servers behind a Load Balancer running Apache with PHP we're finding that people can't hold an SSL session. You can access any page on the site using https by adding https:// to the URL but when you click a link even though that link will show https you get redirected back to a standard http page.
On the Load Balancer listener page I have it set up as:
HTTP 80 to HTTP 80
TCP (SSL) 443 to TCP 80
I've tried non-TCP and using https and I've tried 443 to 443 but that throws a Server 503 error (server overload). I've added a *:443 VirtualHost on the servers but that didn't work.
I also even tried a:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://www.mydomain.com/$1 [R=301,L]
as an .htaccess rule. But users are still being redirected back to HTTP when navigating.
Any ideas?
I would guess the right track is having HTTPS 443 to HTTP 80, not TCP. Can you provide more details about what happens when you configure it this way?