0

Please note that I have asked this question on "server fault", nothing turned up there, so posting on SO.

I have requirement where user will type url like http://example.com/Welcome in browser, but I need to send it to http://myip.com/someapp/next.html, so I wrote virtual host in httpd.conf file:

<VirtualHost *:80>
     ProxyRequests off
     ProxyPreserveHost On
     RewriteEngine On

     RewriteRule "^/(.*)" "http://myip.com/someapp/next.html" [P]
     ProxyPassReverse "/" "http://myip.com/someapp/next.html"

</VirtualHost>

This is working partly. When user enter url http://example.com/Welcomeit is being replaced with http://example.com. How can I keep complete url (http://example.com/Welcome)? would appreciate any help.

EDIT: Here is the access_log surrounding the call

184.180.123.46 - - [06/Dec/2017:21:10:41 +0000] "GET /myip.com/images/logo.png HTTP/1.1" 200 6697 "http://example.com/Welcome" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"
184.180.123.46 - - [06/Dec/2017:21:10:51 +0000] "POST /myip/somepage HTTP/1.1" 200 7 "http://example.com/Welcome" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"
184.180.123.46 - - [06/Dec/2017:21:10:52 +0000] "GET / HTTP/1.1" 200 3391 "http://example.com/Welcome" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"
184.180.123.46 - - [06/Dec/2017:21:11:01 +0000] "GET / HTTP/1.1" 200 3391 "http://example.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"
kosa
  • 65,990
  • 13
  • 130
  • 167
  • 1
    nothing in that configuration would replace a request for `http://example.com/Welcome` to `http://example.com`. That would reverse proxy /Welcome or any other request (.*) to the destination you specify. So either you are not expression correctly what you want to achieve or you are looking at the wrong config. – Daniel Ferradal Dec 07 '17 at 01:43
  • @ezra-s I am not expert httpd, mod_rewrite, so your comment might be very valid about my confusion. This is the only config I have in my httpd.conf. What I want to achieve is, keep the original url in browser url box but on backend forward every request to the url I have configured here like (http://myip.com/someapp/next.html). I am 100% sure that I don't have anything else because this is brand new thing I am trying since yesterday. thanks for your time! – kosa Dec 07 '17 at 03:36
  • @ezra-s updated question with access_log statements surrounding the call. – kosa Dec 07 '17 at 03:54
  • 1
    `GET /myip.com/images/logo.png HTTP/1.1" 200 6697 "http://example.com/Welcome"` <-- This just means that your /Welcome, that is `http://myip.com/someapp/next.html`just have references to `/myip.com/images/logo.png`, so the problem here is not the actual directives (although I don't like the unnecessary use of mod_rewrite here, but the contents of the "backend" response itself. – Daniel Ferradal Dec 07 '17 at 10:48
  • You are correct--> http://myip.com/someapp/next.html has references to images/logo, I am not sure how this impacts on stripping out app context (/Welcome) from the url in browser? What can I do it keep it as http://example.com/Welcome and keep serving the images and pages from /myip.com/someapp? appreciate any help. – kosa Dec 07 '17 at 17:03
  • 1
    you will simply have to make more specific Reverse proxy directives. Right now what you do is "reverse proxy every request to a single item" where you will need to reverse proxy / to /somethinginthebackend, and if the backend contents refer to itself you have to "change the backend content" or try to do difficult substitutions with mod_sed or mod_proxy_html, etc. A nightmare awaits you, fix the backend so it does not reference to itself, it must only use uri-path instead of whole URL to reference its contents then reverse proxy will be piece of cake. – Daniel Ferradal Dec 08 '17 at 15:35
  • @ezra-s Thanks for your suggestion. These terms are little new to me, let me read them and try your suggestions. Appreciate your time and help! – kosa Dec 08 '17 at 16:02

0 Answers0