rewrite cgi-bin with tomcat

New to mod_rewrite? This is a good place to start.

rewrite cgi-bin with tomcat

Postby rockcod » Mon May 18, 2009 8:55 am

hi
I serve services using Tomcat. How do I make a rewrite rule so that it people can access it thru the cgi-bin directory (ie, www.blah.com/cgi-bin/script.cgi).

The servlet is at: www.blah.com/Production/servlet/myservlet
I would like users to be able to access it via GET/POST at: www.blah.com/cgi-bin/script.cgi

Thanks in advance.
rockcod
 
Posts: 4
Joined: Mon May 18, 2009 8:41 am

Postby richardk » Mon May 18, 2009 11:23 am

Try the following in a .htaccess file in your document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^cgi-bin/script\.cgi$ /Production/servlet/myservlet [QSA,L]


If it doesn't work:
Do you have access to the httpd.conf file?
Do you have a /cgi-bin directory?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby rockcod » Mon May 18, 2009 1:47 pm

thanks for the reply.

Yes, I do have access to the httpd.conf and that's where I'm making the change. Anyway, I've tried your post and it doesn't work. That's actually one of my 1st attempts after searching the forums. The following seems to work but for some reason, it excludes my content-length from the response headers.

RewriteEngine On
RewriteRule ^cgi-bin/script\.cgi /Production/servlet/myservlet [PT,L]

comments?
rockcod
 
Posts: 4
Joined: Mon May 18, 2009 8:41 am

Postby rockcod » Mon May 18, 2009 2:03 pm

A little correction. It seems to be excluding the contentlength headers when Tomcat is running on a different server. Things look fine when Apache and Tomcat are running on the same machine. Not sure if it's my bad rewrite rule or something else. Any ideas?
rockcod
 
Posts: 4
Joined: Mon May 18, 2009 8:41 am

Postby richardk » Tue May 19, 2009 3:55 pm

Yes, I do have access to the httpd.conf and that's where I'm making the change.

Where in the httpd.conf file? A <VirtualHost>, <Directory> or the main server configuration?

It seems to be excluding the contentlength headers when Tomcat is running on a different server. Things look fine when Apache and Tomcat are running on the same machine. Not sure if it's my bad rewrite rule or something else.

I doubt it's a bad RewriteRule or at least if it is because of mod_rewrite i doubt you can change the behaviour with mod_rewrite. What configuration are you using to tell Apache the pages are on a different server? (Mod_proxy, the tomcat module.)
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby rockcod » Tue May 19, 2009 5:15 pm

I'm doing within the virtualhost container. Also using mod_jk with worker to communicate with tomcat. Do my rewrite look fine?
rockcod
 
Posts: 4
Joined: Mon May 18, 2009 8:41 am

Postby richardk » Wed May 20, 2009 8:29 am

The mod_rewrite pattern should probably be
Code: Select all
^/cgi-bin/script\.cgi$
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 92 guests

cron