5

I have a website hosted to root domain say www.example.com. Can I do the mapping as follows-

www.example.com/portal1 mapped to www.portal1.com
www.example.com/poral2 mapped to www.portal2.com
www.example.com/portal1/product/product1-> www.portal1.com/product/product1
www.example.com/portal2/product/product1-> www.portal2.com/product/product1

Please note that all the urls mentioned on left hand side are working correctly (mapping is done). Portals are variable so there can be n number of such portals.

Thanks in advance for help

Sumit
  • 401
  • 2
  • 6
  • 21

4 Answers4

1

You cannot do the following mapping with DNS servers, those servers handle domain name only. e.g. www.example.com -> www.portal2.com or example.com -> www.example.com

But you can do this mapping with 301 redirects.

This question is a little bit similar.

Community
  • 1
  • 1
Jack Wire
  • 681
  • 12
  • 25
  • Thanks for reply @Jack Wire! 301 redirects will show resultant urls in browsers address bar. So for example if user requests www.portal1.com from browser, 301 will redirect it to www.example.com/portal1. Later url will also be visible on address bar of browser. We want user to feel like he is still browsing www.portal1.com – Sumit Jan 22 '17 at 07:06
  • I didn't know you wanted the redirect to be invisible to the users. In that case you have to use the solution of @pedrofb. It will create an invisible redirect to the target url. – Jack Wire Jan 23 '17 at 13:24
1

You can use Tomcat rewrite module

Create a empty ROOT context in Tomcat (without any deployed applications in it). Put a context.xml file in your webapps directory, under the ROOT/META-INF, with the following content

<?xml version='1.0' encoding='UTF-8'?>
<Context docBase="ROOT" path="/" reloadable="true" crossContext="true">
   <Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />
</Context> 

Set also a rewrite.config file in the ROOT/WEB-INF directory with this content

RewriteCond %{HTTP_HOST}  ^www.portal1.* [NC]
RewriteRule ^/(.*)$ /portal1/$1 [L]
RewriteCond %{HTTP_HOST}  ^www.portal2.* [NC]
RewriteRule ^/(.*)$ /portal2/$1 [L]
pedrofb
  • 37,271
  • 5
  • 94
  • 142
0

Yes. You can do redirect through the URL rewrite in web/application level, for example IIS URL rewrite, Apache.

anguspcw
  • 306
  • 2
  • 18
0

It took me lot of RnD to finally arrive to the solution I was exactly looking at. Most of the answers given are partially corrert. However the requirement was very typical and I have solved it in following way.

I have developed a servlet which checks for host names (valid hostnames are kept in database) and valid url patterns and make appropriate routing. (Server side routing). This also includes checks for how further routing takes place like if somebody visits www.porta1.com and clicks link on it he should land on www.portal1.com/aboutus.

I know lot of hard work, but works exactly what was needed.

Sumit
  • 401
  • 2
  • 6
  • 21