Forcing HTTP to HTTPS in httpd.conf giving blank page - ssl

I am using amazon ec2 instance and i have created a load balancer and uploaded my SSL certificate. I am able to hit https://www.example.com but i can also hit http://www.example.com .So i want to force all the http to HTTPS. How can i do this?
I have tried:
<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} http
RewriteRule https://www.example.com%{REQUEST_URI} [L,R=301]
</VirtualHost>
But i get a blank page after restarting httpd.I can see the shortcut icon in the windows bar but i see a blank page. How can i fix this?

Have you tried https://wiki.apache.org/httpd/RedirectSSL? It is simpler to use when compared to rewrites. If you must use rewrites, give https://wiki.apache.org/httpd/RewriteHTTPToHTTPS a try

Related

How to do this Apache mod-rewrite redirect transparently

I have this redirect (in Apache 2.4 VirtualHost *:80 configurations), which redirects example.com over to example.com/api/ (subfolder) and it works flawlessly.
Once I enter http://example.com into the browser, it takes me directly to http://example.com/api/.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/$
RewriteRule (.*) /api$1 [R,L]
Now, what I need is for this to work transparently. I want http://example.com/api to load directly on the root domain: http://example.com
I've tried all kinds of suggestions I found on the internet, but nothing that would hide/mask the subfolder from the final URL that shows in the browser.
I figured there is an easier solution to this. I am running my app on a Tomcat server behind Apache and thus adding the following to Apache rules into VirtualHost config fixed the issue with subfolder transparency.
ProxyAddHeaders off
ProxyPass / http://server-host-for-example-com:8080/connect/
ProxyPassReverse / http://server-host-for-example-com:8080/connect/

My homepage wont go through HTTPS port

So my domain is [1] and as you can see whenever you go on that link it will get HTTP (without padlock) but if you go to any other link it will be HTTPS. Only my homepage goes through HTTP.
Important things to mention is that I use Apache.
Every my attempt to edit .htaccess file ends up by website stoping to work. My whole website is hosted on AWS and that is where I derived my SSL certificate.
I want to make that homepage load in HTTPS as well.
How should I do that?
Here is my app folder and place where I created my .htaccess file.
[1]:
Adding this to your .htaccess should do it:
RewriteEngine on
RewriteCond %{HTTPS} =off
RewriteRule ^$ https://www.urtina.com/ [L,R=301]
If it breaks Apache, check the error log. It is for the homepage only as requested.

Redirection https to https within same Apache

I have a requirement where I have to redirect my hostname to particular application which is again hosted on same Apache. Let's take an example, When I hit on host(https://domain1.example.com), It should internally redirect me to Apache Web Application (https://domain1.example.com/application1) without changing the browser URL.
I am not sure how to achieve SSL to SSL redirection. Thanks in Advance..!!!
This should work. This will redirect all incoming urls that are going to domain1.example.com/ to domain1.example.com/application1
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain1.example.com$
RewriteRule ^$ https://domain1.example.com/application1 [L,R=301]
If without changing browsing URL is your goal then PROXY is your way.
Put following in your apache vhost or global file,
ProxyPass https://domain1.example.com/ https://domain1.example.com/application1
ProxyPassReverse https://domain1.example.com/ https://domain1.example.com/application1
PS shibboleth has nothing to do with this, at least you have not mentioned any case.
EDIT
ProxyPass should come to virtural host not in location
Ideally all the location tag should be out of virtual host

HTTPS redirection on AWS ELB

We have web servers running Apache behind an AWS ELB. I have setup the ELB to accept HTTPS connections, and send the requests over HTTP to the webservers. This works fine.
I have also redirected all the requests to ELB from HTTP to HTTPS using HTTP:X-Forwarded-Proto.
I have added the below virtualhost section to my httpd.conf file and restarted Apache. This setup is redirecting HTTP requests to HTTPS but it is landing on the Apache home page instead of the expected site.
ServerName www.myexample.com
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule !/index.html https://%{SERVER_NAME}/%{REQUEST_URI} [R=301,L]
The configuration seems to be simple and straightforward but not working.
Please let me know what is wrong in the above setup and why is it landing on the Apache home page.
You should escape the . in your rewrite rule. Change your Rewrite to be:
RewriteRule "!/index\.html" https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Also, as in the comment to your OP Remove the slash between %{HTTP_HOST}%{REQUEST_URI}

Apache redirect after a rewrite

I'm trying to figure out how to properly do this. I'm hosting a domain that used to have a website also on the same server, however the website has now been moved to a different machine, but they want to keep the domain hosted on our DNS. Rather than changing the DNS record right now, I'm trying to figure out how to do a proxy redirect but I'm having some trouble.
Right now, I'm using the RewriteEngine to rewrite the URL as follows:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.domain\.org [NC]
RewriteRule ^/(.*) http://www.domain.org/$1 [L,R]
This is in case someone looks up the website simply by http://domain.org it will get rewritten to http://www.domain.com - that works fine.
Now I need to redirect it to go to an IP address with a username:
http://111.222.333.444/~user
Rather than simply redirecting it to that address, I'd like to do a proxy where the domain will still be visible in the browser's address bar, while also keeping the above rule in place.
Suggestions anyone?
Make sure mod_proxy is enabled and do:
<VirtualHost *:80>
ServerName www.domain.com
ProxyPass / http://111.222.333.444/~user
</VirtualHost>