Apache mod_rewrite internally to different port

后端 未结 2 458
再見小時候
再見小時候 2021-02-06 06:08

Is it possible to internally redirect (so url won\'t change in address bar) with mod_rewrite to different port on same host? Eg

http://host.com:8080 -> http:/         


        
2条回答
  •  不要未来只要你来
    2021-02-06 06:27

    Elaboration on the mod_proxy solution with [P], the proxy flag:

    1. Enable modules mod_proxy and mod_proxy_http:

      a2enmod proxy proxy_http
      

      Without these two enabled, you'd later get a 300 Forbidden status and the error message "AH00669: attempt to make remote request from mod_rewrite without proxy enabled" in the logs.

    2. Place the following into the Apache2 vhost config section for the forwarding host:

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

      This includes a technique by Steve Webster to prevent malicious URL crafting, explained here. Not sure how to deal with appending the GET parameter in this context, though.

    3. Restart Apache2:

      sudo service apache2 restart
      

提交回复
热议问题