How to redirect based on response code.

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

How to redirect based on response code.

Postby chintan_kachhi » Mon Jul 13, 2009 8:27 am

I am trying to use mod_rewrite to be able to redirect to my custom html error page, when a 404 is returned. Right now, I have my http server running and my appserver(Websphere) running. When I take down a service on the appserver, it returns a message as follows:

SRVE0255E: A WebGroup/Virtual Host to handle localhost:80 has not been defined.

I want to be able to redirect to my custom error message, based on the response, rather than show this error message. Trying to use the ErrorDocument directive within the httpd.conf file does not work,... but I have heard that this is possible to do with mod_rewrite. I am not sure how to do this.
chintan_kachhi
 
Posts: 2
Joined: Mon Jul 13, 2009 8:19 am

Postby richardk » Wed Jul 15, 2009 12:41 pm

You cannot do this with mod_rewrite. Mod_rewrite runs at the beginning of the request.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby chintan_kachhi » Thu Jul 16, 2009 7:09 am

Ok looks like something like the folllowing would be acceptable, if I can get it to work:

Here's the link:

http://fixunix.com/websphere/373084-use ... opped.html


where one of the relevant responses for me was:

I don't believe you'll find a solution to this that has acceptable
performance.

There may be a way to do this with mod_rewrite and the LA (lookahead)
flag, but that effectively doubles the load of the traffic going to WAS.

You might look at having your administrators touch a magic file in IHS
during the redeploy of the app, and teaching mod_rewrite to return a
custom error page when that file exists.

This doc will partially help:

http://publib.boulder.ibm.com/httpse...alter_uri.html

RewriteCond /opt/IHS/conf/applicationdown.txt -f
RewriteRule ^/app1/foo /errormessage.html [PT]




I am trying the last two lines where I do a rewrite condition and the rewrite rule.

But seems like this is not working either... is there a particular place where the applicationdown.txt and errormessage.html files need to be?
My document root is C:/WebSphere/IBMHTTPServer/htdocs/en_US


I tried putting the applicationdown.txt in my IHS/conf directory,
For my rewrite rule, i put:
RewriteRule ^/app1 /errormessage.html
where errormessage.html was put under my document root directory. But this still does not work. Am I using the right directory structure to run this module?
chintan_kachhi
 
Posts: 2
Joined: Mon Jul 13, 2009 8:19 am

Postby richardk » Thu Jul 16, 2009 2:03 pm

Are you using a .htaccess file?

There may be a way to do this with mod_rewrite and the LA (lookahead)
flag, but that effectively doubles the load of the traffic going to WAS.

What variable would be set with the responce status in it? You can try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{LA-U:STATUS} ^404$
RewriteRule ^app1(/.*)?$ /404errormessage.html [L]


RewriteCond /opt/IHS/conf/applicationdown.txt -f
RewriteRule ^/app1/foo /errormessage.html [PT]

I am trying the last two lines where I do a rewrite condition and the rewrite rule.

But seems like this is not working either... is there a particular place where the applicationdown.txt and errormessage.html files need to be?
My document root is C:/WebSphere/IBMHTTPServer/htdocs/en_US

I tried putting the applicationdown.txt in my IHS/conf directory,
For my rewrite rule, i put:
RewriteRule ^/app1 /errormessage.html
where errormessage.html was put under my document root directory. But this still does not work.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond C:/WebSphere/IBMHTTPServer/conf/applicationdown.txt -f
RewriteRule ^app1(/.*)?$ /errormessage.html [L]

Make sure C:/WebSphere/IBMHTTPServer/conf/applicationdown.txt is the correct path.
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 99 guests

cron