1

i need to map a sub-domain (which is created by user, it means dynamically) to a same login page but i want to get the subdomain parameter through address bar

for exmaple

www.xyz.koopsz.com

www.abc.koopsz.com

www.mno.koopsz.com

these urls should redirect to the login page with paramater xyz or mno etc

  • What i did

i thought i can map it in .htaccess www.koopsz.com/abc then will rewrite it to abc.koopsz.com

after so many effors i get to know that

apache tomcat doesn't support htaceess

now how can i solve this problem in Apache tomcat i read about virtual hosting but everytime when user add i have to make changes in server.xml i need it in a runtime. please help me out.

Aman
  • 806
  • 2
  • 12
  • 38
  • I suppose "htaceess" is just a typo here on SO and not in your real error message? – Hulk Aug 09 '16 at 05:40
  • Is there a reason you need to alter the URL at all? Why not just let the user access the application using `www.foo.koopsz.com` and use the default host for every request? You can get the hostname from the request to discover the `foo` at any time... it doesn't need to be at the beginning of the hostname. – Christopher Schultz Aug 10 '16 at 03:52
  • @ChristopherSchultz in www.foo.koopsz.com .. foo is the subdomain which is created by user at runtime – Aman Aug 10 '16 at 04:27
  • If DNS isn't an issue, you not just point all hostnames at the same server (or cluster) and use the hostname the user uses to detect which configuration to use (presumably, you want to use the same application but a different database or whatever depending upon which user it is)? You wouldn't need to change the Tomcat configuration from the default: use just the default host for everything with a single application deployed. – Christopher Schultz Aug 10 '16 at 12:02

1 Answers1

0

I believe you are looking for Tomcat's rewrite valve. Other questions here more directly explain how to set this up. From Tomcat 8 URL Rewrite we see: in conf/server.xml

<Host name="my.domain.com" appBase="webapps/MyDomainServer" unpackWARs="true"
           autoDeploy="true"
           xmlValidation="false" xmlNamespaceAware="false">
  <Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />
  <!-- access logging, aliases,...-->
</Host>

and in conf/Catalina/my.domain.com/rewrite.config

RewriteCond %{REQUEST_URI} ^/(css|img|js|partials|rest|favicon).*$
RewriteRule ^.*$ - [L]

RewriteRule ^.*$ /index.html [L,QSA]

You should mostly be able to plug in whatever htaccess directives you were using for rewrite.

Community
  • 1
  • 1
craigts
  • 2,857
  • 1
  • 25
  • 25