Typical Domain Mapping Requirement

I have a website hosted in the root domain, for example www.example.com. Can I make 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 links indicated on the left side are working correctly (matching is performed). Portals are variables, so the number of such portals may be n.

Thank you in advance for your help.

+5
source share
4 answers

It took me a lot of RnD to finally come up with a solution that I definitely looked at. Most of the answers are given partially corrert. However, this requirement was very typical, and I solved it as follows.

I developed a servlet that checks hostnames (valid hostnames are stored in the database) and valid url patterns and does the appropriate routing. (Server side routing). This also includes checking how further routing occurs, for example, if someone visits www.porta1.com and clicks a link to it, he must land at www.portal1.com/aboutus.

I know a lot of hard work, but it works exactly what you need.

0
source

You cannot perform the following mapping to DNS servers; these servers only process the domain name. 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 bit like.

+1
source

You can use Tomcat rewrite module

Create an empty ROOT context in Tomcat (without any deployed applications in it). Place the context.xml file in the webapps directory under ROOT/META-INF with the following contents

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

Also rewrite.config file in the ROOT/WEB-INF with this content

 RewriteCond %{HTTP_HOST} ^www.portal1.* [NC] RewriteRule ^/(.*)$ /portal1/$1 [L] RewriteCond %{HTTP_HOST} ^www.portal2.* [NC] RewriteRule ^/(.*)$ /portal2/$1 [L] 
+1
source

Yes. You can redirect via URL rewriting at the web application level, for example, rewrite the IIS URL, Apache.

0
source

Source: https://habr.com/ru/post/1258331/


All Articles