Forum Moderators: phranque

Message Too Old, No Replies

Apache with Tomcat 4 - Can 301 redirect work?

When running Tomcat 4 within Apache is it still possible to use .htaccess?

         

Mr_X

4:49 pm on Nov 11, 2004 (gmt 0)

10+ Year Member



Hi

My site runs in Tomcat 4 within Apache. Is it still possible to use .htaccess for 301 redirects?

As I understand it Apache reads .htaccess and causes the redirect but it does not work where my site is hosted.

Any ideas?

Please, no guessing.

Thanks.

jdMorgan

5:23 pm on Nov 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Mr_X,

Welcome to WebmasterWorld!

> but it does not work where my site is hosted.

Please post your relevant .htaccess code and define "does not work". Otherwise, all replies will be guesses.

Do you get a 500-Server Error response to requests with your code in place? If so, what's in the server error log?

Or does it appear that nothing happens at all?

Have you tried a simple test -- for example, rewriting a non-existent page to your home page, like


Options +FollowSymLinks
RewriteEngine on
RewriteRule ^test\.html$ /index.html [L]

and then requesting the non-existent test.html page?

Jim

Mr_X

5:50 pm on Nov 11, 2004 (gmt 0)

10+ Year Member



I've done 301 redirects successfully on other non-java web sites so .htaccess syntax is not the problem.

The administrator of the site in question seems to be saying Tomcat cannot handle 301 redirects, which I think is correct.

But, Tomcat is running within Apache and Apache can handle 301 redirects from .htaccess, so my question is:

Will Apache handle the redirect before passing the request on to Tomcat?

Has anyone out there successfully used .htaccess in an Apache/Tomcat setup?

Thanks

Mr_X

6:12 pm on Nov 11, 2004 (gmt 0)

10+ Year Member



Hi Jim

Thanks for the reply it's appreciated. I just re-read my reply and I have to say it looks a bit short and abrupt and a little rude.

I'm sorry, it wasn't meant to be, it's just that I'm juggling 10 things at once...

Anyway...

It was some time ago but I just got the old page, no error and no redirect.

The .htaccess was like this:

redirect 301 /old_page.htm [mydomain.co.uk...]

As for this lot:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^test\.html$ /index.html [L]

I don't really know anything about Apache so you've lost me. I develop using Tomcat standalone and it's only when I deploy that Apache enters the scene.

So please look to the message above for the actual question.

Regards

jdMorgan

7:27 pm on Nov 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you're on Apache pre-2.0, look at the order of the LoadModule and AddModule directives in httpd.conf. Those loaded first are executed last. Therefore if you load Tomcat *after* mod_alias, then it will run *before* mod_alias, and mod_alias may never run, and the Redirect directives may never be processed.

On Apache2.0, there is some kind of priority system in place, as opposed to using the load order, and I can't claim to know anything about it.

Most of the people who post replies here are busy, so we understand.

Jim

Mr_X

2:29 pm on Nov 12, 2004 (gmt 0)

10+ Year Member



Hi Jim

This is the reply from the hosting guy, he seems to be sure that 301 redirect do not work when using both Apache and Tomcat.

Other people must have come up against this problem, it's probably the most common web server setup around...

You can to see all mod_alias directives at [httpd.apache.org...]

I have been trying to use Redirect directive with .htaccess on your site. No success because Apache forward request to Tomcat-Apache connector and request processed by Tomcat. I’m sure same effect will be with Alias directive because it processed by same Apache module.

Please look to Apache directives that configure Apache-Tomcat forwarding:

<Location "/context">
RemoveHandler .html
JkUriSet group tomcat4
</Location>

When Apache receive any request matched to /context, this request forwarded to Apache-Tomcat connector without any next handling by Apache. Usage of Redirect may be possible, for example, if you need to redirect any other path that not matched with Apache-Tomcat forwarding path - /anypath

One way is possible in your cause – processing by Tomcat.

Please look to Struts service documentation. Possible Struts could be configured to process these redirects. Please reply with Struts possibility for this configuration.

Anyone else want to chip in?

Regards

Lyndon

bcc1234

2:47 pm on Nov 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use a proxy (from within mod_redirect) to pass requests to tomcat instead of using mod_jk or such. Then you can use any apache features you want. If you don't need to handle something like 50 requets per second then you won't notice performance difference, but it sure makes life easier when you can explicitly define which urls are passed to tomcat and which are not.