Solved

Proxy Pass + Mod Rewrite

Posted on 2009-03-30
7
1,005 Views
Last Modified: 2013-11-22
I am trying to re-write only a particular file type. In this case its .jsp - The problem is that the re-write rules are trying to re-write everything to tomcat. I am using:

<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_URI} !^/addurl
    RewriteRule /*.jsp ajp://127.0.0.1:8009%{REQUEST_URI} [P]
</IfModule>

This works however for any subdirectory such as the one in the example I have to add a rule otherwise its being sent to tomcat. Is there a better way to do this? The reason I am doing this is because the site is comprised of mixed content including Java (.jsp), PHP, and HTML

 Any help would be greatly appreciated as this is a time sensitive issue.
0
Comment
Question by:Sam Cohen
[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
  • 4
  • 3
7 Comments
 
LVL 27

Accepted Solution

by:
caterham_www earned 500 total points
ID: 24021913
Other files, which should not go through tomcat have jsp in their path as well?
RewriteEngine on
# ending with .jsp
RewriteRule \.jsp$ ajp://127.0.0.1:8009%{REQUEST_URI} [P]

Open in new window

0
 
LVL 8

Author Comment

by:Sam Cohen
ID: 24022257
Sorry for the delay, and yes there are other files within the same directory that should not go through tomcat. There is a mixture of php, java and html within the same folder. I tried the rules you provided and it works for "index.jsp" however other paths such as domain.com/path/ do not work and return this error.

HTTP Status 404 - /addurl/index.jsp

type Status report

message /addurl/index.jsp

Also with that said I tried your rules without having "index.jsp" as a directory index type, and without that domain.com/path/ does work, however the index page is .jsp so therefore that no longer works.
0
 
LVL 27

Expert Comment

by:caterham_www
ID: 24022598
> HTTP Status 404 - /addurl/index.jsp

> type Status report

> message /addurl/index.jsp

That reads like a typical message from tomcat, not apache http server, which means that the request is being proxied but something went wrong at tomcat's side.
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 8

Author Comment

by:Sam Cohen
ID: 24022885
In that particular path /addurl there is no JSP, its only php in that particular folder. Thats the problem I am trying to find a way to fix. The root directory is similar to this:

domain.com/ contains java, html and php
domain.com/path/ contains php
domain.com/path2/ contains php and or html

When using the mod rewrite rule that I included in my original post it proxies only *.jsp in the root directory, but tries to proxy any sub directories also which do not contain java.

0
 
LVL 27

Assisted Solution

by:caterham_www
caterham_www earned 500 total points
ID: 24022941
How does your DirectoryIndex look like? Is there an index file for that folder? You should specify jsp files at the end of the list, e.g.


DirectoryIndex index.php index.jsp

Open in new window

0
 
LVL 8

Author Comment

by:Sam Cohen
ID: 24022999
Awesome! Combine the rewrite rules and changing the Directory index shes working like a charm!

I had:
DirectoryIndex index.jsp index.php index.htm index.html

which I changed to:
DirectoryIndex index.php index.htm index.html index.jsp

restarted apache(doing this from vhost config, not .htaccess) and she came right up! Thanks!
0
 
LVL 8

Author Closing Comment

by:Sam Cohen
ID: 31564466
Awesome this helped alot! thanks!
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Introduction and Prerequisites This article describes methods for detecting whether a client browser accepts and returns HTTP cookies and whether the client browser runs JavaScript.  Most client browsers will, by default, be configured to use cooki…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

687 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