Proxy https requests and add a query param - apache

I am not very experienced with Apache. What I want to do is to have a proxy server that I can use on a browser or with mobile clients to intercept HTTPS traffic to specific domains, then add a query param to the corresponding request and forward it.
With Apache I got it working using mod_rewrite for HTTP requests like so:
RewriteEngine On
RewriteCond %{QUERY_STRING} !PARAM
RewriteRule ^/(.*)$ http://%{HTTP_HOST}/$1?PARAM=SOME_FIXED_VALUE [P,QSA]
But not for https. I guess its related to the encryption and me changing the request.
I own the SSL certificate - so I could use it to offload the traffic if necessary for the change.
I am somehow stuck on how to do it though and if this is possible. Any help would be appreciated. If its not possible with Apache, I am also open for other possibilities.

Related

Where to handle the redirection from HTTP to HTTPs?

I have a heroku application with a domain from godaddy.
My site is built with node and express.
My website is www.juanitacalendar.de and I want it to always redirect to HTTPS (no matter if the users types the www or not).
Should I handle this within Heroku? Within node/express? In my index.html?
I've read in another answer that I'm suppose to use this code that has to do with apache. I am clueless on where to put this piece of code though.
RewriteEngine On
RewriteCond %{HTTPS} !^on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
There are many ways you could achieve this.
In your situation, it looks like you can get Node/Express.js to redirect for you. See this answer for more information: Heroku NodeJS http to https ssl forced redirect.

Redirect to https version on a DNS level with AWS?

Since Cloudflare has the option to redirect all http:// traffic to https:// with the setting "Always Use HTTPS", does AWS have the same feature?
I'm using Route 53 and EC2. I want to redirect http to https (SSL) on a DNS level, so it doesn't hit my server and put server load.
This is my .htaccess code:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I want to redirect http to https (SSL) on a DNS level
The DNS level only cares about mapping between names and IP addresses (at least the part relevant for this question). It is impossible to make the browser use a different application protocol (HTTPS vs HTTP) and/or port (443 vs 80) at the DNS level.
If you use CloudFront with Route53 you can achieve this functionality:
Or you can use route53 with an elastic load balancer to redirect http to https traffic.

Redirect request to another domain with mod_rewrite

Is it possible in Apache to redirect a request from my domain: www.example.com/index.html to another domain http://www.other-domain.com/page/info as if I was directly visiting that page?
So the user shouldn;t notice anything. He should simply think he's visiting www.example.com, while apache serves back the content of http://www.other-domain.com/page/info.
This is because the other domain is the new server, and the users should be able to visit the old URL as well. Note, I dont want to do a 301 redirect.
I know this can be done with VirtualHost, but my web host doesn't allow me to use that. I can use mod_rewrite, so I'm hoping I can do the same trick with that.
Anyone any idea if t his is possible, and if so, how to do it?
RewriteEngine on
RewriteRule ^/index.html$ http://www.other-domain.com/page/info [PT]
Only way to achieve this is by enabling mod_proxy on www.example.com. Once mod_proxy and mod_rewrute are enabled place this rule in DocumentRoot/.htaccess of www.example.com:
RewriteEngine On
RewriteRule ^/?(index\.html)?$ http://www.other-domain.com/page/info [L,P]

Apache redirection to sub domain

My website URL till now was as per this pattern https://www.xyz.com, from which i served both static and dynamic contents. https://www.xyz.com defaults to home page, https://www.xyz.com/static/index.html, and dynamic contents are served from https://www.xyz.com/dyna/login.jsp.
Recently I added an additional webserver and got sub domain registered from which I plan to serve static content through http URL scheme instead of https, and only serve dynamic pages from https URL. So, if user types https://www.xyz.com, should redirect to http://static.abc.com.
Webserver: Apache 2.x
My Queries are:
a. How to configure apache to redirect request on https://www.xyz.com to http://static.abc.com while ensuring that request to https://www.xyz.com/dyna/login.jsp does not get redirected?
Will this have any noticeable performance overhead?
b. If redirection from http to https and also launching http screen from https page lead to any security warning in this case?
Note that I do not intend to submit any data from http to https and vice versa, it will be just URL redirection or links.
c. How to make the redirection cacheable?
use .htaccess to define https://www.example.com/static/index.html as https://www.example.com/index.html
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain/static/index.html [NC]
RewriteRule ^(.*)$ domain/index.html$1 [L,R=301]

Apache http server rewrite or redirect

I have a functioning environment with an apache http server (load balancer) with a cluster of tomcat servers at the back end. I am stumped by one problem though, I am not able to redirect or rewrite the request url to what I need. for example,
request url - http://www.yyy.com
i would like to redirect or rewrite it to
http://www.yyy.com/mycontext
I tried redirect and rewrite with no luck.
RewriteRule ^/$ http://www.yyy.com/mycontext/ [L] - Error (can't fine the url)
AND then I tried this,
Redirect / http://www.yyy.com/mycontext/ - this results in the following,
http://www.yyy.com/mycontext/mycontext/mycontext/mycontext/mycontext/........... repeats.
I am not able to figure out the right condition statement. I tried using the server variables to write a rewritecond but I am doing something wrong and it gets ignored.
Any assistance is appreciated. I have not had much experience in this area.
And this ProxyPass / http://www.yyy.com/mycontext/ is in the config for www.yyy.com?
yes in the virtualhost
Not sure how your load balancer could ever possibly work. You are proxying requests back to yourself, and it's going to instantly run out of threads because each proxied request runs on its own thread.
Request for / arrives at your virtual host
ProxyPass reverse proxies it to http://www.yyy.com/mycontext/, which is itself
Request for /mycontext/ arrives at your virtual host
ProxyPass reverse proxies it to http://www.yyy.com/mycontext/mycontext/
Request for /mycontext/mycontest/ arrives at your virtual host
ProxyPass reverse proxies it to http://www.yyy.com/mycontext/mycontext/mycontext/
etc.
I think what you're probably looking for is:
RewriteCond %{REQUEST_URI} !^/mycontext/
RewriteRule ^(.*)$ /mycontext/$1 [L]
But this has nothing to do with your load balancer or your tomcat server.