Solved

How RewriteEngine works in Apache web server for Load Balancer

Posted on 2014-11-07
5
65 Views
Last Modified: 2015-04-08
I have following lines in my httpd.conf of a server which is behind a load balancer (AWS ELB)

<VirtualHost *:80>
#for instances behind AWS LoadBalancer
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
## Below you need to use escape character \ before the period's in ELB CNAME. For example, my-test-elb-0000002951\.us-east-1\.elb\.amazonaws\.com
RewriteCond %{HTTP_HOST} !^my_application-1973433045\.eu-west-1\.elb\.amazonaws\.com$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L,NE]
</VirtualHost>

Open in new window


I would like to understand what it does.
0
Comment
Question by:beer9
  • 3
  • 2
5 Comments
 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 40429927
Please see my answer to your other question for most of the details.  For the rest, see my comments below:
<VirtualHost *:80>
#for instances behind AWS LoadBalancer
RewriteEngine On
# checks to see if the HTTP header X-Forwarded-Proto is equal to the string "http"
RewriteCond %{HTTP:X-Forwarded-Proto} =http
## Below you need to use escape character \ before the period's in ELB CNAME. For example, my-test-elb-0000002951\.us-east-1\.elb\.amazonaws\.com
# check that the requested host is not "my_application-1973433045.eu-west-1.elb.amazonaws.com"
RewriteCond %{HTTP_HOST} !^my_application-1973433045\.eu-west-1\.elb\.amazonaws\.com$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L,NE]
</VirtualHost>

Open in new window

0
 

Author Comment

by:beer9
ID: 40429963
so if my application client.myapplication.com is CNAME to AWS ELB my_application-1973433045.eu-west-1.elb.amazonaws.com then I can can not access my application using my_application-1973433045.eu-west-1.elb.amazonaws.com URL I have to have to use client.myapplication.com ?
0
 

Author Comment

by:beer9
ID: 40429964
same thing if I want to access it via ip of my domain/ELB then that will also not be served?
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 40430309
The domain will be served in both cases.  However, the rewrite will only take effect on requests if the host is *not* "my_application-1973433045.eu-west-1.elb.amazonaws.com".
0
 

Author Comment

by:beer9
ID: 40430971
when I access my_application-1973433045.eu-west-1.elb.amazonaws.com then I gets redirected to https://my_application-1973433045.eu-west-1.elb.amazonaws.com/my_application then it shows

The page you were looking for doesn't exist.

You may have mistyped the address or the page may have moved.

Open in new window


what is causing it to redirect to https://my_application-1973433045.eu-west-1.elb.amazonaws.com/my_application ?


Thanks!
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now