Apache mod_rewrite internally to another port

Is it possible to internally redirect (so the URL will not change in the address bar) from mod_rewrite to another port on the same host? For instance,

http://host.com:8080 -> http://host.com:9999/myapplication/?param=val
+5
source share
2 answers

1, enable mod_proxy

LoadModule  proxy_module         modules/mod_proxy.so
LoadModule  proxy_http_module    modules/mod_proxy_http.so

2, you must configure apache for vhost:

<VirtualHost *:8080>
    ....
    ProxyPass / http://host.com:9999/myapplication/?param=val
    ProxyPassReverse / http://host.com:9999/myapplication/?param=val

</VirtualHost>

3, also install VHost on port 9999

More details here:

+5
source

Development of mod_proxy solution with [P], proxy flag:

  • Enable mod_proxy and mod_proxy_http modules:

    a2enmod proxy proxy_http
    

    300 "AH00669: mod_rewrite - " .

  • Apache2 vhost :

    <VirtualHost *:8080>
      
      RewriteEngine on
      RewriteCond  %{REQUEST_URI}  !^$
      RewriteCond  %{REQUEST_URI}  !^/
      RewriteRule  .*              -    [R=400,L]
    
      RewriteRule  (.*)  http://host.com:9999/myapplication/$1?param=val  [P,L]
      
    </VirtualHost>
    

    , URL-, . , GET .

  • Apache2:

    sudo service apache2 restart
    
+1

All Articles