Funnel URL's to single CGI? ReWrite is looping

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

Funnel URL's to single CGI? ReWrite is looping

Postby kettlewell » Sat May 23, 2009 4:07 pm

Hello -

I've got a cgi (stealth.cgi) that needs to take most URLs and funnel them through the CGI. (I think I can filter out the URL's that I don't want there)

Internally to the CGI, I use the pathinfo portion to dictate what happens.

so stealth.cgi/something
should redirect to stealth.cgi and pathinfo gets handed to the CGI.

I had this working on my own system but had a separate directory for cgi-bin and all was good.

Now I'm faced with my CGI being in the same directory as my HTML directory... something I hadn't planned on....

I've tried many different incantations of the following, but most of them end up in an infinite loop.

domain.com/stealth.cgi/stealth.cgi/stealth.cgi/stealth.cgi

Code: Select all

DirectoryIndex stealth.cgi

Options ExecCGI Indexes  FollowSymLinks
AddHandler cgi-script cgi pl

ReWriteOptions MaxRedirects=2

ReWriteEngine on
ReWriteBase /

#ReWriteCond %{REQUEST_URI} !\.css$
#ReWriteCond %{REQUEST_URI} !\.png$
#ReWriteCond %{REQUEST_URI} !\.jpg$
#ReWriteCond %{REQUEST_URI} !\.jpeg$
#ReWriteCond %{REQUEST_URI} !\.gif$
#ReWriteCond %{REQUEST_URI} !\.html$
#ReWriteCond %{REQUEST_URI} !robots.txt$

#ReWriteRule ^(one)$ /stealth.cgi/one [L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
ReWriteRule ^(.*)$ /stealth.cgi/$1 [NS,R,L]



As a side note, my previous setup would not display the CGI in the URL , so I'd have www.domain.com and NOT www.domain.com/stealth.cgi....

What options do I have here?

I'm saavy, but never gotten in depth with mod_rewrites, and am feeling a bit out of my league here.


Any direction of a good approach would be very much appreciated.

Thanks

Matt
kettlewell
 
Posts: 1
Joined: Sat May 23, 2009 2:47 pm

Postby richardk » Sat May 23, 2009 4:24 pm

The R flag causes a visible redirect instead of an internal rewrite. When you do a redirect it's a totally new request and the NS flag and
Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} ^$

do not work.

Code: Select all
AddHandler cgi-script cgi pl
DirectoryIndex stealth.cgi
Options ExecCGI Indexes  FollowSymLinks

RewriteEngine On

#RewriteCond %{REQUEST_URI} !^/.+\.(css|gif|html|jpe?g|png)$
#RewriteCond %{REQUEST_URI} !^/robots\.txt$

RewriteCond %{ENV:REDIRECT_STATUS} ^$
ReWriteRule ^(.*)$ /stealth.cgi/$1 [QSA,L]
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 113 guests

cron