Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Tomcat / mod_rewrite Conflicts with extensionless requests

Posted on 2007-03-19
3
Medium Priority
?
995 Views
Last Modified: 2013-12-02
I have been having too many fruitless conversations with support representatives lately, so I figured maybe I'd have a better chance getting an answer here. This is a complicated problem though; I didn't just set it at 500 points for no good reason (which I sometimes do).

One of my websites is hosted by GoDaddy.com, using their "Deluxe Linux Plan":
https://www.godaddy.com/gdshop/hosting/shared.asp?app%5Fhdr=&ci=5652#tabs

I created my whole website in PHP and had it running just fine. I even used some mod_rewrite rules so that certain files could be called without a file extension. For instance, this one:

    RewriteRule ^search$ search.php [NC,L]

You probably all know how that works already, if someone asks for mydomain.com/search it will load up search.php, even though they didn't ask for that.

So everything worked. In fact, everything worked *perfectly*. But then I decided that I wanted to add some special kinds of functionality to my site--in particular, functionality that can be achieved better with Java than with PHP. So I went to the hosting control panel, and clicked the button to "enable support for Java."

This takes a little while to process, and effectively turns on Apache Tomcat. I know very little about Tomcat, just that it's needed for Java in many cases. Ever since I did that, my site doesn't really work anymore.

Any RewriteRules in .htaccess are completely ignored for extensionless requests, and I based a good deal of my site on such requests. So now, if I try to access mydomain.com/search, I get a 404 error instead of seeing the search.php as I should.

I found the article below on the GoDaddy Help Center. It has a long list of file extensions that are handled by Apache, while "files not appearing in this list are processed by Tomcat" and therefore "bypass [the .htaccess] settings." And since my "extensionless" requests obviously are not on this list, it is clear that any corresponding RewriteRules are being bypassed completely.
http://help.godaddy.com/article.php?article_id=1133

WHAT I WOULD LIKE TO KNOW:
Is there some fix for this? Some way to tell Apache/Tomcat/Whatever that it should process the htaccess settings for "extensionless" files? And more importantly, is there some concise set of instructions I can tell the support reps to do in order to resolve this issue?

Thanks very much in advance. You don't want to know some of the answers that the support reps gave me. I really appreciate any help you guys can offer.
0
Comment
Question by:soapergem
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
mrcoffee365 earned 2000 total points
ID: 18757479
You seem to have the basic answer to your question, which is that the RewriteRules in .htaccess are being  ignored (at least for files without an extension) and they are being passed to Tomcat.

So, since the files are being passed to Tomcat, you could put things to handle those files in Tomcat.

The cleanest Tomcat solution would be to put a filter in that would check the request file name, see that it doesn't have an extension, and respond with a browser redirect to your search.php file.  It's not clear that you have access to Tomcat for that kind of thing at GoDaddy, so you might have to do something else.

You could put a custom 404 error handling page in Tomcat which would check if there's no extension, and redirect to your search.php page.  That might be more possible with GoDaddy, although you would have to check with them.

You could bypass the Tomcat problem by putting an extension on your links (or whatever is producing extension-less requests) and have that extension handled by your .htaccess rewrite rules.

Capturing all requests of a certain type in Tomcat is a little different from the way that Apache handles it, so using Tomcat's web.xml file to capture all files without .jsp or whatever your Java code extensions are (/servlet/* perhaps) is trickier.  You don't really get regular expression manipulation in the web.xml file.  You can define what Tomcat does for
/*
/something/*
In this case, you would change all your extension-less requests to have /something/ in front of them.  Then you would have a servlet receive any of those requests and redirect the user to search.php.  Or forward, if that's better.
0
 
LVL 6

Author Comment

by:soapergem
ID: 18757548
Well, after several more futile attempts at pumping any ounces of help out of their support department, I realized this was pretty much a lost cause as far as they were concerned. So I'm in the process of disabling Java, just to get things working again. Thanks for your detailed solution, though, it was very informative!
0
 
LVL 27

Expert Comment

by:mrcoffee365
ID: 18757877
Well, good luck.

The reason you need Tomcat is that Apache only processes HTML.  It has other apps to process things like PHP, Perl, and Java (JSP or servlets).  The PHP handling is bundled with the Apache release, so it's the easiest for an ISP to turn on for its customers.  You need a servlet engine like Tomcat for JSP or Java servlet pages, which is why Tomcat was turned on.  It's odd that the GoDaddy people decided to send everything not defined in the Apache host to Tomcat, but that probably works for most of their customers.  I imagine it's related to the fact that servlets are often handled with an extension-less name in URLs.

If you decide to turn Java on again, then the best solution for you at GoDaddy is probably to get a default servlet for everything that comes to your site (in this case, all requests that Apache hands off to Tomcat) and have that servlet check the file name.  If there's no extension, in your case you want to forward or redirect the browser to the search.php page.  If there's an extension that means you want Java (.jsp or if you use .do for servlets, then .do), then the main servlet would forward to the right Java page.
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month9 days, 2 hours left to enroll

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question