[development] Can .htaccess discard part of a path?

Jamie Holly hovercrafter at earthlink.net
Tue Nov 10 20:57:09 UTC 2009


If there is no real way to figure out the new page from the old string 
then you could redirect it to a generic 404 page, or an internal Drupal 
page (or anything really):

RewriteEngine on
RewriteBase /
Rewritecond %{QUERY_STRING} ^q=cgi-bin(.*)$
RewriteRule .* {put your new URL here - keep the space between the * and 
URL}? [R=301,L]

That would redirect any query that has q=cgi-bin at the beginning to the 
new page (static 404, the front page, etc.).

If there is a way to figure up your own content then a simple module 
would come into play here. Check for $_GET['q'] equaling the cgi-bin 
line and for $_GET['file']. Do it on something like hook_init and then 
have some code figure the post from the $_GET['file'] and do a 
drupal_goto based on the result. If nothing is found then just do a 404.


Jamie Holly
http://www.intoxination.net 
http://www.hollyit.net



Jennifer Hodgdon wrote:
> Nancy Wichmann wrote:
> > I put this in there already    
> RewriteRule ^cgi-bin/printOriginal.pl/$ 
> http://www.example.com [R=301,L]
> > And I am still seeing these come through to the Drupal log.
>
> You said the URLs that were problems looked like this:
>
> http://www.example.com/index.php?q=cgi-bin/printOriginal.pl&file=/alpha/beta/gamma/rage_prevention.shtml
>
> The regular expression above ends in $,  which is the regexp special 
> character meaning "end of the string/line". So it would only match a 
> URL that ended with "printOriginal.pl/". You need something after that 
> to match the rest of the URL... Something like:
>
> ^cgi-bin/printOriginal.pl/.*
>
> Might work a bit better... (Caveat: I'm not an expert on Apache 
> .htaccess redirects either.)
>
>     -- Jennifer
>
>   


More information about the development mailing list