4

Here is the scenario -

I have a website where customer's websites run under mine.

So as an example, my domain is www.mainsite.com and a customer's website would be www.customer1.com --- but when someone goes to customer1.com, the index.html file will redirect them to my site under www.mainsite.com/customers/index.jsp?number=1000.

An example of the index.html with a redirect to my site:

<html>
<head>
<META HTTP-EQUIV=REFRESH CONTENT="0;URL=http://www.mainsite.com/customers/index.jsp?number1000">    
</head>
</html>

Is it possible to add a rewrite directive using mod_rewrite that will take the customer's domain, such as www.customer1.com and not only redirect it to my site with the variable named "number", but also mask the rest of the pages accessed thereafter?

So that it would appear to anyone browsing the site that they were "still" under customer1.com and not see mainsite.com instead?


Edit

The customer's website/domain is hosted on the same vps as my own website. My site is built on JSP pages.


katura
  • 2,177
  • 14
  • 39
  • 48

2 Answers2

2

Not using mod_rewrite, but there's mod_proxy, which does what you want (you need to enable and load the module, it is not enabled in default config):

<VirtualHost *:80>
  ServerName yoursite.example.com
  ProxyPass / http://maskedsite.example.net/
  ProxyPassReverse / http://maskedsite.example.net/
</VirtualHost>

Note that 1) this makes all the "masked" traffic appear to come from your host (instead of the user's host), and also 2) any load on the masked host will go through yours.

See e.g. this for more details: http://www.apachetutor.org/admin/reverseproxies

Piskvor left the building
  • 91,498
  • 46
  • 177
  • 222
  • Since the customer's domain is hosted on my vps along with my own website, would I still use mod_proxy? I thought mod_rewrite could handle this. – katura Apr 20 '11 at 13:27
1

Why you dont use the <jsp:forward> instead of mod_rewrite ?

Cristian
  • 327
  • 2
  • 9
  • Assuming the server can work with Java Server Pages, that is (most Apache servers don't have this by default, IIRC). – Piskvor left the building Apr 19 '11 at 15:39
  • I wrote this because i seen index.jsp and i thought he's using Java Server Pages – Cristian Apr 19 '11 at 15:46
  • My site is built on JSP pages - so yes, I have JavaServerPages enabled. But I want to have the STATIC index.html (not DYNAMIC .jsp) page up on the customer's domain ---- since the search robots (not wanting to change the subject here) will look at the static content and not so much the dynamic. – katura Apr 19 '11 at 15:48
  • @Cristian: Aha, good catch, didn't notice that. However, the docs you're linking to say "The target file can be an HTML file, another JSP file, or a servlet, **as long as it is in the same application context as the forwarding JSP file.**" (emphasis mine) - is this applicable? (I don't know) – Piskvor left the building Apr 19 '11 at 15:49
  • Question - would really keep the customer's domain in the address bar for each request of the user's session? – katura Apr 19 '11 at 15:50
  • Ofc yes, forward is an internal jsp function that load another page without letting the browser know about it. @Piskvor eheheh, 1 to 0 for me :) – Cristian Apr 19 '11 at 15:58
  • @Piskvor & Cristian - since the customers site wouldn't be in the same application context as the forwarding JSP file, won't work for me. The 'url' has to be relative or absolute. Any other suggestions? – katura Apr 20 '11 at 13:30