This post documents the process of setting up a reverse proxy to load one (Origin) website in the subdirectory of another. During this process the reverse proxy directives will also append HTML to the head and body of the origin website.



The instructions below are based on an Apache Linux server running cPanel/ Web Host Manager. The set-up requires the following Apache modules:

  • mod_proxy
  • mod_proxy_http
  • od_include
  • mod_headers
  • mod_rewrite
  • mod_sed

mod_sed is the only uncommon module, however it is only required if you are using the OutputSed directives, if you don’t plan on making any modifications to the origin website you can skip it.



The server will already be preconfigured to listen for additional .conf files for each domain once they’re added to the correct directories. For the standard WHM/cPanel/Apache combination:


Where $user is the Linux user account associated with the hosting package, $domainname is your cPanel domain name and $file is the .conf filename.



ProxyPass Directives

Inside reverseproxy.conf the Reverse proxy directives are added:

  • /subdirectory where the origin website will be displayed (could be root “/”)
  • is the origin website
ProxyPreserveHost off
SSLProxyEngine on
SSLProxyVerify off
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off
ProxyPass "/subdirectory" ""
ProxyPassReverse "/subdirectory" ""


# Stop any existing rewrites on subdirectory
RewriteRule ^(subdirectory)($|/) - [L]

<Location "/subdirectory">

     <IfModule mod_headers.c>
        RequestHeader unset accept-encoding
        Header unset Content-Length

     # Add new layout fields
     Options +Includes
     AddOutputFilterByType Sed;INCLUDES text/html
     OutputSed "/<!--#[a-zA-z]/d"
     OutputSed "s/\\(<\/head>\\)/\\<!--#include virtual=\"\/layout\/\"--><\/head>/g"
     OutputSed "s/\\(<body[^>]*>\\)/\\<!--#include virtual=\"\/layout\/\"-->/g"
     OutputSed "s/\\(<\/body>\\)/\\<!--#include virtual=\"\/layout\/\"--><\/body>/g"


The above code will automatically try to include additional files in the pages processed by ProxyPass.

  • layout/ will be appended to the <head>
  • layout/ will be added to the start of <body> tag
  • layout/ will be added just before the </body> tag

These files can be used to apply style/scripting on top of the code supplied by the proxy.


Rebuild and Restart Apache

Once the reverse proxy directives have been added to the Apache configuration, the live conf file needs to be rebuilt to include the new directives:


The rebuild process will flag any errors with the reverse proxy code. These can then be rectified before a successful rebuild.

Then the obligatory Apache restart:




Hello, I'm Keith, a website developer in Belfast, Northern Ireland working with PHP, Magento, Shopify and WordPress.

I've been building websites for over 10 years, from custom website development to bespoke web applications, Shopify and Magento ecommerce and Online Leaning Environments. I've worked on a range of projects and am always looking out for the next interesting project.

Related Notes Posts

Apache VirtualHost with Reverse Proxy

This post documents the process of setting up a reverse proxy to load one (Origin) website in the subdirectory of another. During this process the... August 2021 · Notes

Upcoming changes to eBay's PayPal Payments

Over the course of 2021 eBay will be incrementally changing how it works with sellers. Changes include updates to the fee structure, how fees are... June 2021 · Notes

Choose a better browser

A run down of the most popular web browsers including Firefox, Chrome, Edge and Opera as well some alternate options if you'd like something different.... May 2021 · Notes

More Notes Posts...