SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Httpd, Tomcat, mod_rewrite Subdomain Issue

    So I have been struggling with an issue with Apache web server and Apache Tomcat app server set up in a proxy setup. Here is the scenario:

    We have our Java web application and when we deploy it and go to our web site it works great. I will change the names for sake of security. So if I go to example.com/ourapp/index.html the web server will forward the request to Tomcat and the application will load fine.

    Now we have some folders under ourapp that direct us to different locations. For example, if I go to example.com/ourapp/folderA/index.html it loads one page and if I go to example.com/ourapp/folderB/index.html it goes to another. I think you get the point.

    Now I want to use subdomains to direct users to these folders so the URLs are pretty. So I set up an .htaccess file to rewrite the URLs. This is what the .htaccess file looks like:

    Code:
    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
    RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com [NC]
    RewriteRule (.*) /ourapp/%1/index.html [NC,QSA,L]
    Now when I go to http://folderA.example.com/ A page loads (because I get no 404) but none of the resources inside the HTML page loads. All of the resources (images, CSS files, JavaScript files, etc) are defined as relative links to /ourapp/folderA or /ourapp/folderB respectively.

    I think this has something to do with our Java app having a path of /ourapp because when I manually type in http://folderA.example.com/ourapp/css/stylesheet.css the file will load.

    What I want to do is when someone goes to the subdomain that it rewrites so the relative paths will still work. I need the rewrite to take into account the application folder (ourapp/). I hope this all makes sense. Thank you in advance for your assistance.

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,650
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    viper,

    I'm a bit confused as to where your subdomains are pointing. If they are pointing at their subdirectory on the main domain, they do NOT have (relative link) access to the files outside their own directory (it's a "webspace" issue for that [sub]domain). Please clarify.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let me give you an example that will hopefully clarify what I am talking about. Lets say we have a stylesheet called screen.css. In our original setup the file would be at a URL of example.com/ourapp/folderA/css/screen.css. What I would like is to have the URL be folderA.example.com/css/screen.css. Inside the HTML file, the file is linked using a relative URL like this: css/screen.css where this is relative to example.com/ourapp/folderA. I hope this helps. Thanks again.

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,650
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Actually, I asked about apples and you responded with oranges.

    If you have a subdomain that is functioning properly, it's registered with your DNS server as well as your local VirtualHost with a physical address for the DocumentRoot (each domain/subdomain is treated like a separate domain). Are your subdomains using the domain's DocumentRoot as their own or are they using their subdirectory as their DocumentRoot (if the later, then example.com/ourapp/{anything but folderA} is outside folderA's DocumentRoot/file structure and cannot be accessed with relative links.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry about that. I guess I didn't understand your question. I am sort of new at this server stuff.

    I am pretty sure we have the subdomains still pointing to the domain's document root (which I don't think includes /ourapp/). We are trying to do this subdomain stuff as dynamically as we can so when we add a folder underneath /ourapp/ (like /ourapp/folderA) we automatically get the subdomain without having to go into Apache's configuration each time. That is why we are trying to use mod_rewrite.

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,650
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    viper,

    This forum is about learning so don't worry about not understanding. I'm here to help you (and other members) learn. When I get pedantic with one, it's not meant as an insult but to teach others who may not wish to ask the necessary question: Why?

    Okay, my first thought was that your subdomains have no business working UNLESS they've been setup as subdomains (if you're using cPanel, it's the subdomains button - but that creates a DocumentRoot pointing to the subdirectory with the name of the subdomain by default). However, it seemed that your subdomains are working, ergo the question.

    Of course, if the server (i.e., httpd.conf) is yours, then you could have Dynamically configured mass virtual hosting (wildcard subdomains) setup.

    Without seeing your .htaccess, I have to ask why you're not using relative links (assuming a common DocumentRoot) or absolute links (assuming different DocumentRoots for each (sub)domain). Care to comment?

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  7. #7
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do have complete control over the server. The app is not on any sort of shared hosting. We do have wildcard subdomains set up because we do have one other subdomain that is already functioning as intended. Inside all of our HTML pages we have relative links. The links are either relative to the current page or relative to our Java app's context root. I will explain using my earlier example.

    If our domain is example.com and I am visiting example.com/ourapp/folderA/index.html, all the paths should be relative to /ourapp/ (context root). When I move it over to a subdomain like folderA.example.com/index.html, I still want my relative links to for. For exmaple, I have a relative link in the index.html file that looks like this: ../images/testimage.png. This goes up one folder from folderA/ into the ourapp/ and then back down to the images/ folder. I want that to still work in the mod_rewrite subdomain setup.

    I guess what I am saying is I want my document root to include /ourapp/. But our app is a Java app that is running on Tomcat. Apache is just the front for our application. It is proxying all requests to Tomcat (via proxy_ajp) sitting behind Apache so the web server has limited understanding of the application.

    I hope this all makes sense.

  8. #8
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,650
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    viper,

    Well, I still don't know where the DocumentRoots are located, main domain and subdomains. That is a problem for me (and, perhaps, Apache). However, a bigger problem (for me) is the Tomcat as I have no knowledge of its operation nor of how it "plays with" Apache.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  9. #9
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The document root in apache hasn't changed from the default. It is still domain root (/ or example.com/). This is for all domains and subdomains as far as I can tell because we are only using apache for proxying requests over to Tomcat.

    No worries if you don't know Tomcat. I appreciate all your help regardless if a solution is provided. Thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •