Sunday, April 17, 2016

Apache Virtual Host Rule for Configure the url based on context root – Virtual Host Proxy Pass and ReWrite Rule

ProxyPass and ProxyPassReverse directives are used to direct the traffic from webserver to apache server. For configuring the proxy, we can configure with mod_proxy and mod_jk. Mod_jk forward the request to an application server via AJP protocol. 

In the below configuration, we are configured the request to Tomcat application server. The public domain listens to the port number 98. If the request comes with context root, it will direct to the application server and will serve the request. If the application is starting with language parameter, then it will redirect to the application with different context root. Below entries can be customized for your requirments and add it in httpd-vhosts.conf file.

<VirtualHost *:98>
    DocumentRoot "/u01/apache/htdocs/mysite"
    ServerName public.domain.entry


       ProxyPass /contextroot http://x.x.x.x:port/contextroot
       ProxyPassReverse /contextroot http://x.x.x.x:port/contextroot

       RewriteEngine On
       RewriteOptions Inherit
       RewriteLog "/u01/apache/logs/rewrite_log.log"
       RewriteLogLevel 8
        RewriteRule "^/$" /ar/index.html [R=301,L]
       RewriteRule ^/en/(.*)$ /Application_ContextRoot/$1?languageCode=en&%{QUERY_STRING} [P,L]
       RewriteRule ^/ar/(.*)$ / Application_ContextRoot /$1?languageCode=ar&%{QUERY_STRING} [P,L] 

       Include conf/modjk/uriworkers.properties
  
       ErrorLog "/u01/apache/logs/error_log"
       CustomLog "/u01/apache/logs/access.log" common

</VirtualHost>


No comments:

Post a Comment