Redhat – Using apache ProxyPass to forward URL on new site to old webserver

apache-2.2mod-proxyproxypassredhatreverse-proxy

We are currently moving our site to a CMS, and in the process moving to a different server. There is some code on the older server that we do not want to move to the new server. We want the URLs to be the same, so we have been looking at (and currently using) ProxyPass. The old server actually does this to remap URLs to both public and internal content. The <Proxy> directive on the old server is still commented out and it works fine.

I have tried placing the following in several places, inside a virtual host directive, outside of it, etc. I get no errors starting apache, but it never works.

ProxyRequests On
Order allow,deny
Allow from all
ProxyVia On
ProxyPreserveHost On
ProxyPass /tester/ http://oldserver.companyname.com/app1/
ProxyPassReverse /tester/ http://oldserver.companyname.com/app1/

I have tried several examples, much less permissive than this, much simpler, etc.

Apache seems to ignore the tester, and sends it along to the CMS which then returns a 404. We would like to have tester mask the old URL, which is what we currently do on our other machine.

This particular virtual host does have a few rewrite rules, and I have tried placing these before or afterwards as well. The modules are loaded earlier in the httpd.conf. Currently running apache 2.2.

As of right now – nothing happens. No errors, no logs (that I see), etc. It's like the rules aren't actually there.

One thing I did notice – it works fine in our other virtual host directive. The only difference is the other one is much smaller, and doesn't contain some rewrite rules for WordPress.

Here is an example of my VirtualHost

<VirtualHost *:80>
    ServerAdmin webmaster@site.com.local
    DocumentRoot /var/www/html/wordpress
    ServerName wptest    
    ServerAlias wptest.site.com.local

    ErrorLog /var/log/httpd/wordpress-error-log
    CustomLog /var/log/httpd/wordpress-access-log common

    ProxyPass /tester http://www.company.com/app1

    RewriteEngine On   

    <IfModule mod_rewrite.c>
      #RewriteBase /wordpress/
      # Switched the logging on 2/15/13 JMD
      RewriteLog "/var/log/httpd/rewrite_log"
      RewriteLogLevel 4

    # From https://stackoverflow.com/questions/13235180/how-to-remove-trailing-slash-for-folder-index-html-when-index-html-is-stri

    # If it's a request to index(.html)
    RewriteCond %{THE_REQUEST} \ /(.+/)?index(\.html)?(\?.*)?\  [NC]
    # Remove it.
    RewriteRule ^(.+/)?index(\.html)?$ /%1 [R=301,L]    

     RewriteCond %{REQUEST_URI} \.html$
     RewriteRule ^(.*)\.html$ $1 [R=301,L]    

      RewriteRule ^/index\.php$ - [L]
      RewriteRule ^/css/(.*) /wp-content/themes/our2012/css/$1 [QSA,L]
      RewriteRule ^/js/(.*) /wp-content/themes/our2012/js/$1 [QSA,L]
      RewriteRule ^/img/(.*) /wp-content/themes/our2012/img/$1 [QSA,L]
      RewriteRule ^/font/(.*) /wp-content/themes/our2012/font/$1 [QSA,L]
      RewriteRule ^/plugins/(.*) /wp-content/plugins/$1 [QSA,L]
      RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
      RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]    
   </IfModule>
</VirtualHost>

(crossposted from StackOverflow per request)

Best Answer

If your CMS is using Mod rewrites in an .htaccess, domain.com/test may be getting handled before the proxypass.

something you may consider is using a rewrite rule with a [p] flag along with your wordpress rewrite rules.

(untested rule quickly thrown together as an example)

RewriteRule /test/$ http://oldserver.example.com/ [P]
ProxyPassReverse /test/ http://oldserver.example.com/

http://httpd.apache.org/docs/current/rewrite/flags.html#flag_p

Another link with information about using mod_rewrite to Proxy
http://httpd.apache.org/docs/2.2/rewrite/proxy.html