Gordo
Gordo

Reputation: 75

Apache proxying subdomain root requests

Description

Use Case A

Use Case B

VirtualHost definition

Attempt 1

    # RewriteRules
    RewriteEngine On
    RewriteRule ^/(.*) http://internal:8080/foo-website/$1 [P]

Attempt 2

    # RewriteRules
    RewriteEngine On
    RewriteRule ^/$ http://internal:8080/foo-website/$1 [P]

Upvotes: 4

Views: 6719

Answers (3)

Bruno Grieder
Bruno Grieder

Reputation: 29814

ProxyPass rules match in order

 ProxyPass        /webservice/ http://internal:8080/foo-webservice/
 ProxyPassReverse /webservice/ http://internal:8080/foo-webservice/

 ProxyPass        /website/ http://internal:8080/foo-website/
 ProxyPassReverse /website/ http://internal:8080/foo-website/

 ProxyPass        / http://internal:8080/foo-website/
 ProxyPassReverse / http://internal:8080/foo-website/

No rewrite rule. Isn't that good enough ?

Upvotes: 3

Gordo
Gordo

Reputation: 75

  • I think the issue with Attempt 2 (none of the files in the js, img or css folders being mapped) was a sign that my approach was wrong.

  • My solution now is to redirect any requests to the root, to the foo-website webapp.

            <VirtualHost *:80>
                    ServerName foo.domain.com
    
                    ProxyRequests Off
    
                    <Proxy *>
                            Order deny,allow
                            Allow from all
                    </Proxy>
    
                    ErrorLog /var/log/apache2/foo_error.log
                    LogLevel warn
                    CustomLog /var/log/apache2/foo_access.log combined
    
                    # RewriteRules
                    RewriteEngine On
                    RewriteRule   ^/$  /foo-website/  [R]
    
                    # ProxyPass
                    ProxyPreserveHost On
                    ProxyPass        / http://internal:8080/
                    ProxyPassReverse / http://internal:8080/
            </VirtualHost>
    
  • This was not what I originally wanted, but I think this is the resolution.

Upvotes: 0

James C
James C

Reputation: 14149

I think that you need to use the first attempt but include the QSA (query string append) flag in the square brackets at the end of each RewriteRule directive.

Upvotes: 0

Related Questions