issue with rewrite to perl script for missing files and j2ee

Discuss practical ways rearrange URLs using mod_rewrite.

issue with rewrite to perl script for missing files and j2ee

Postby droz578 » Thu Mar 26, 2009 9:44 am

Hey all,
Having a weird issue with the mod_rewrite directive that I'm trying. Bacically I want the redirect any traffic that does not have a valid file or directorty off to a perl script that I have written.
Also for have the Weblogic plug-in module installed. When Rewrite is on and the configuration below is active I'm unable to access and files on the Weblogic server. Has anyone run into this before?


Here are the examples:
Redirect this to perl script: http://localhost/me
Use valid file on server: http://localhost/test/iamhere.html

Configuration thus far:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /cgi-bin/redirector.cgi$1 [L]

Thanks
Droz578
droz578
 
Posts: 6
Joined: Thu Mar 26, 2009 8:11 am

Postby richardk » Thu Mar 26, 2009 10:23 am

Mod_rewrite -d and -f CondPatterns can only check if files exist on the local filesystem.

You could try the U flag
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond wrote:'-U' (is existing URL, via subrequest)
Checks whether or not TestString is a valid URL, accessible via all the server's currently-configured access controls for that path. This uses an internal subrequest to do the check, so use it with care - it can impact your server's performance!

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond http://the-weblogic-server/$1 !-U
RewriteRule ^(.*)$ /cgi-bin/redirector.cgi$1 [L]


If that does not work you will need to exclude all the Weblogic URLs
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
# Ignore /Weblogic/URLs/*
RewriteCond %{REQUEST_URI} !^/Weblogic/URLs(/.*)?$ [NC]
RewriteRule ^(.*)$ /cgi-bin/redirector.cgi$1 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby droz578 » Thu Mar 26, 2009 11:21 am

Thanks for the fast reply. I ended up using this setup:
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{REQUEST_URI} !-U
RewriteRule ^(.*)$ /cgi-bin/redirector.cgi$1 [L]

The weblogic based files are fine but nothing is being passed to the perl script. I turned on logging and here is the information:
127.0.0.1 - - [26/Mar/2009:14:14:26 --0500] [127.0.0.1/sid#fcb08][rid#23db88/initial] (2) init rewrite engine with requested uri /nothing
127.0.0.1 - - [26/Mar/2009:14:14:26 --0500] [127.0.0.1/sid#fcb08][rid#23db88/initial] (3) applying pattern '^(.*)$' to uri '/nothing'
127.0.0.1 - - [26/Mar/2009:14:14:26 --0500] [127.0.0.1/sid#fcb08][rid#241b98/subreq] (2) init rewrite engine with requested uri /nothing
127.0.0.1 - - [26/Mar/2009:14:14:26 --0500] [127.0.0.1/sid#fcb08][rid#241b98/subreq] (3) applying pattern '^(.*)$' to uri '/nothing'
127.0.0.1 - - [26/Mar/2009:14:14:26 --0500] [127.0.0.1/sid#fcb08][rid#241b98/subreq] (2) rewrite /nothing -> /cgi-bin/redirector.cgi/nothing
127.0.0.1 - - [26/Mar/2009:14:14:26 --0500] [127.0.0.1/sid#fcb08][rid#241b98/subreq] (2) local path result: /cgi-bin/redirector.cgi/nothing
127.0.0.1 - - [26/Mar/2009:14:14:26 --0500] [127.0.0.1/sid#fcb08][rid#241b98/subreq] (2) prefixed with document_root to /app/docroot/cgi-bin/redirector.cgi/nothing
127.0.0.1 - - [26/Mar/2009:14:14:26 --0500] [127.0.0.1/sid#fcb08][rid#241b98/subreq] (1) go-ahead with /app/docroot/cgi-bin/redirector.cgi/nothing [OK]
127.0.0.1 - - [26/Mar/2009:14:14:26 --0500] [127.0.0.1/sid#fcb08][rid#23db88/initial] (1) pass through /nothing
droz578
 
Posts: 6
Joined: Thu Mar 26, 2009 8:11 am

Postby droz578 » Thu Mar 26, 2009 6:05 pm

Okay so I have tried something else that might this task a little easier. Want I want to do is goto the url http://localhost/cars and then have it redirect to http://localhost/redirector?uri=/cars and still be able to be aware of the other links from the J2ee server. This is the current configuration that have so far but is still not working. Any help would be apperciated.

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{REQUEST_URI} !-U
RewriteRule ^(.*)$ /redirector?uri=%{REQUEST_URI}
droz578
 
Posts: 6
Joined: Thu Mar 26, 2009 8:11 am

Postby richardk » Fri Mar 27, 2009 1:46 am

Are the Weblogic files on the same local filesystem?
Are all the Weblogic files in one URL (eg. are they all /something/...)? Or do they have a specific extension?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby droz578 » Fri Mar 27, 2009 4:03 am

the weblogic files are on a remote system that is accessable via there plug-in. And all weblogic stuff is in the same url
droz578
 
Posts: 6
Joined: Thu Mar 26, 2009 8:11 am

Postby droz578 » Fri Mar 27, 2009 4:09 am

example url: http://localhost/cars

with this new setting that i setup, all I want to happen now is to check if the url is valid, this should look on the local file system and also check the weblogic location, if it is not valid pass the url "/cars" to this url with the url located in this location /redirector?uri=/cars <<<<<------this is a weblogic call now also
droz578
 
Posts: 6
Joined: Thu Mar 26, 2009 8:11 am

Postby richardk » Fri Mar 27, 2009 12:44 pm

What is the Weblogic location/URL? How can mod_rewrite know it's a Weblogic URL?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby droz578 » Mon Mar 30, 2009 6:14 am

Richard,
Thanks for all your help on this problem that I was having. I went ahead and rewrote the perl script and made some additions. So now when they try to reach that page and its not there, using the ErrorDocument 404 directive they will be passed to the perl script which will take the some parameters from the web server and redirect it to the correct locaction based on the url.

Thanks
Droz578
droz578
 
Posts: 6
Joined: Thu Mar 26, 2009 8:11 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 15 guests

cron