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

Mobile-first Web Design

Mobile-first web design Mobile-first web design is a design approach that prioritises mobile devices when designing a website. Instead of designing a website for desktop... January 2023 · Notes

Web development in Northern Ireland

Web development in Northern Ireland is a thriving industry, with many talented and skilled individuals and companies offering a range of services. Northern Ireland is... December 2022 · Notes


Apache, Nginx, PHP, JavaScript and Meta redirects There are two main redirect options **301** for a permanent redirect. Use this when the redirect is pointing... October 2022 · Notes

More Notes Posts...