Apache proxy redirect subdomain to subfolder

Hi , i have droplet hosting on “” and shared hosting on “” i want redirect it by Apache proxy “” to main “” and keep on shared hosting and open it by “” I know this question has been asked at least a million times, but I tried all the solutions but still doesn’t work with me

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi, There are two configuration methods to achieve your main goal (proxying):

  • virtual host configuration
  • htaccess file configuration

The more convenient and recommended method is virtual host block configuration. Due to official Apache docs, this method is simpler and more efficient. However, because your prospective proxy is actually on shared hosting, it is quite likely that the only way you could configure proxy is with htaccess file. So, before you start, ensure with your hosting provider which configuration method is available for you. Anyway, let’s go through both of these configuration methods.

1. Vhost (an abbreviation for virtual host) configuration.


  • Following Apache modules have to be loaded on mod_proxy and mod_proxy_http.

The configuration of vhost on could look like that:

  <VirtualHost *:80>
    ErrorLog /var/www/
    CustomLog /var/www/ combined
    ProxyPass "/"  ""
    ProxyPassReverse "/"  ""

Reverse proxy configuration is highlighted. Some words of explanation for this configuration.

[secondary_label without ProxyPassReverse directive set up]
[secondary_label with ProxyPassReverse directive set up]

2. Htaccess configuration.


  • Following Apache modules have to be loaded on mod_rewrite, mod_proxy, mod_proxy_http, and mod_header.
  • Apache configuration directive AllowOverride has to be set to ON in server configuration. That enables configuration with htaccess file.

Create (or modify if it already exists) an .htaccess file in web root directory of vhost. Note that this file is hidden (its name starts with a dot sign). If you use e.g. FTP client to transfer files to, make sure the visibility of hidden files is turned on in its configuration settings. Here are the directives you need to put into your .htaccess file:

RewriteEngine On
RewriteRule ^(.*)$1 [P]
Header edit Location ^http://example\.com/blog/(.*)$1

Some explanation for the content of this file.

  • RewriteEngine On enables the runtime rewriting engine.
  • RewriteRule ^(.*)$1 [P] defines proxy behavior. Any requested URL ^(.*) will be rewritten as variable $1 to the end of the string, creating new, absolute URL. The request will be redirected due to newly created URL but redirecting server will be acting as proxy, as it is defined with flag [P].
  • Header edit Location ^http://example\.com/blog/(.*)$1 is an equivalent of ProxyPassReverse directive in vhost configuration. In case of any redirection on backend host, proxy receives HTTP location header field containing new URL of redirected resource. Our Header directive replaces URL started with with Thanks to that our proxy behavior is consistent.

Do not forget to restart Apache service after modifying the configuration :)

in CentOS
sudo systemctl restart httpd
in Ubuntu
sudo systemctl restart apache2
Mind the web content caching when you will be testing the results of your settings. Web content might be cached by your web browser, network devices (e.g. home router), internet proxies, CDN etc. Minimize caching impact as much as possible during testing time.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel