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}
Related
Actually I've an amazon ELB configured ONLY with rule HTTPS 443 --> HTTP 80. I cannot open the HTTP (port 80) on ELB for contract reasons.
I see that for all client requests in https without training slash the apache for some unknown reasons redirect it in http with training slash:
https://host/site --> redirect to http://host/site/ (doesn't work)
I see different questions about this problem and seems that all people solve opening HTTP on ELB (it add some header informations as well as X-Forwarded-Proto "https")
And they apply these Rewrite rules:
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
to get it working behind an AWS Elastic Load Balancer.
For me this automatic apache redirect when is missing the trailing slash on the the URL is not clear (for my understanding apache when see an URL without trailing slash that point to a dir, redirect it adding trailing slash)
Is there an alternative way to solve this problem WITHOUT open HTTP on Amazon ELB?
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
in a search from google , i found my domain url with https and not http .
For example : https://xxxx.com/yyyy/zzzz and not http://xxxx.com/yyyy/zzzz
It's possible redirect from https to http for the domain xxxx.com ?
I use centos and apache web server
On the same server, i have a certificate https that respond to https://zzzz.com
Thanks
Carlo
This will work with mod_rewrite on. Put this code in .htaccess file at root of the site.
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
My application is hosted in AWS. It has Apache proxying to tomcat. SSL is terminated at the Elastic Load Balancer, and all traffic is offloaded to port 80.
My need is to have all requests to the site be redirected to SSL. I've been doing a lot of reading about mod_rewrite and have experimented with various solutions I've found on the web, but have not been able to make this work.
To be clear, Apache is successfully proxying requests to Tomcat. It's the redirection to HTTPS that I'm stuck on. Any suggestions would be welcome.
Try with the X-Forwarded-Proto header, e.g.:
<VirtualHost *:80>
...
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=permanent]
...
</VirtualHost>
I have 5 sites on one apache server. One of the sites is with SSL. So when the other sites are accessed with https then they are redirected to the SSL site which is incorrect.
E.g.
https://x.com (with SSL)
http://y.com (normal site no SSL)
If I access https://y.com then I get the content from x.com. How can I fix so https://y.com just gets rewritten to http://y.com?
In your .htaccess put:
RewriteCond %{HTTPS} on [NC]
RewriteRule ^(.*)$ http://y.com/$1 [R=301,L]
You can define it in apache config file. You must add a rule to connection incoming from https port.
If you are using linux, propably you have this config in /etc/apache2/sites-available/default-ssl.
If you don't have this file you must searching https virtualhost:
<IfModule mod_ssl.c>
<VirtualHost _default_:443>