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

Seth Freach sfreach at gmail.com
Tue Nov 10 21:14:48 UTC 2009

a module based solution is possible too, but I'd point out a couple of 
 - a module to handle this will require a Drupal bootstrap to take 
place.  Depending on your site load and resources, this may or may not 
be negligible, and might not be desirable if it can be avoided. This 
might be a non-issue for small or even medium traffic sites...
 - drupal_goto will return a 302 http response code by default.  Be sure 
to specify '301' as the 4th arg to drupal_goto to tell it that this 
resource has moved permanently, not temporarily.


Jamie Holly wrote:
> 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