Mod Rewrite to Replace old /cg-bin/ content?

Mod Rewrite to Replace old /cg-bin/ content?

I just purchased and old domain that has many links and image request to the cgi-bin folder.

I’ve never used anything in the cgi bin, but have good php .htaccess mod_rewrite abilities.

I thought a good solution would be to use mod_rewrite something like this

Rewriterule ^someimage.png cgi-bin/test?name=a234

This was supposed to show the image someimage.png of course i would use cgi-bin/test?name=$1 or similar for all request, but am just testing this on.

Well i get a 403 error

Even using a 301 redirect on the cgi-folder to a main page on the site fails. It gives me a 404 Page Not Found

Anyone have any experience with a similar problem?

Thanks SitePoint

Well there are thousands of links to the cgi-bin as well as thousands of im src calls to a perl generated image. I want to both generate a image to fill that spot, and perform a redirect to keep those backlinks.

Looks like I was way off then… :smiley:

It’s gotta be possible. You got me interested now so I’m going to do some digging and report back.

Hahah, thanks so much man i’ve seen similar post

But i am having problems doing a redirect with all those variables?

This code works, but only with no variables (i dont need to carry the variables over, need to redirect them to some default)

redirect 301 /cgi-bin/test.cgi

I may be way off here but as I understand it the cgi-bin is off limits to the public with most web server configurations. Possibly that is part of the problem?

It all works just fine until i throw a ? in there

About mod_rewrite, this has virtually nothing to do with PHP.

While you will gain some assistance from other PHP developers, you really should pose your query in our Apache Configuration forum instead.
They also have sticky threads such as Mod-rewrite resources and [url=“”]Learn Apache mod_rewrite: 13 Real-world Examples

cant you do this through your .htaccess file… put in a rule to limit access for mod_rewrite ?

Yes he can. The Apache Configuration forum is where he will gain the most help in configuring .htaccess

Hi Mickey!

Some Apache installations place the cgi-bin OUTSIDE your webspace where it’s not subject to .htaccess at all. If this is the case with your host, you may have to suffer through the changes.

TRY: In your DocumentRoot, make a redirect from ^cgi-bin/ to {whatever}/{request handler}.

QUERY_STRING: Don’t worry about the query string with your mod_rewrite or mod_alias (Redirect) as it is a separate Apache variable which is not modified (unless you add a key/value pair and mod_rewrite’s QSA will keep the pre-existing query string in tact).



Hey you guys just checked back in,

Yeah i posted this in the wrong area of SitePoint. For some reason i always associate php and .htaccess (i think its all those old php-nuke Google tapping)

I found the solution, and am posting it.

RedirectMatch 301 /cgi-bin/something?(.*)$1

That will take the variable and pass it to a new page, just the variable.

And yeah .htaccess can override the cgi-bin it must have just been bad code to begin with or something :slight_smile:

Im also sure someone is going to say that is bad regex and it is, ill trim it back and just allow [a-z0-9] or something like that.

Thanks You Guys for sticking with me on this one :slight_smile: