Forum Moderators: phranque

Message Too Old, No Replies

How to not rewrite

not rewrite when cgi folder

         

Learn2Smile

10:59 pm on Nov 15, 2011 (gmt 0)

10+ Year Member



I am not the best at this stuff. This one has stumped me and I can not find an answer.

We have a drupal install, so the .htacess file has the following lines:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]


The issue I have is we have cgi scripts in /cgi-bin/MyFolder/
example
hxxp://www.nodomain.com/cgi-bin/MyFolder/webform.cgi?


These have to be accessible but the rewrite rule above stops this from working.

Does anyone know what I need to do to get past this? If I comment out the rule, the script runs. Of course the rest of the site does not work then.
Thank you!

g1smd

11:22 pm on Nov 15, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteCond %{REQUEST_URI} !=/favicon.ico


The avove line says "don't rewrite requests for favicon.ico"

You need to add another condition that says "don't rewrite requests beginning /cgi...

Learn2Smile

12:55 am on Nov 16, 2011 (gmt 0)

10+ Year Member



Thank you g1smd. I tried with:
RewriteCond %{REQUEST_URI} !^/cgi-bin/MyFolder/


I am guessing I had something wrong there because it did not work.

lucy24

2:01 am on Nov 16, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Leave out the leading slash. In an url, a slash counts as the end of the preceding directory name, not the beginning of the following one.

I just made that up. It makes so much sense and is so straightforward, it can't possibly be right. :(

Then again, you could simply toss the !-f and !-d lines and let your 404 page deal with it.

Learn2Smile

2:58 am on Nov 16, 2011 (gmt 0)

10+ Year Member



Thanks Lucy. The problem line is not the two rewrite conditions though. It is :
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

That is rewriting and not allowing me to the folder. If I comment out that line, I can get where I need to but then the pretty urls do not work in Drupal.

lucy24

4:20 am on Nov 16, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



No, the problem is in the condition:
You need to add another condition that says "don't rewrite requests beginning /cgi...

That's how you prevent the rewrite.

Learn2Smile

4:26 am on Nov 16, 2011 (gmt 0)

10+ Year Member



You are correct on that. I was saying the two conditions you said to remove were not what I needed to get passed. That is why I tried the one I posted. It did not work though. Did I write it wrong or do I have something else that is making it not work.
Thanks :)

lucy24

9:03 am on Nov 16, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Oh, yes, I didn't mean that the !-f was interfering with your Rule. It's just a garbage condition anyway. Well, er, most of the time. Did you try the added /cgi Condition without the leading slash?

As an alternative, you can express the rule as

%{REQUEST_URI} !\.cgi$

This would protect any .cgi scripts even if you later decide to rename the folder they live in.

Learn2Smile

1:07 pm on Nov 16, 2011 (gmt 0)

10+ Year Member



Thank you. I know you have given me the right line. I have it in there now but I must have something else wrong. Maybe in the FilesMatch section?

Here is the full htaccess (minus the php variables):

<FilesMatch "\.(engine|inc|info|install|make|module|profile|test|po|sh|.cgi|.*sql|theme|tpl(\.php)?|xtmpl|svn-base)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$">
Order allow,deny
</FilesMatch>

Options -Indexes

Options +FollowSymLinks

ErrorDocument 404 /index.php

<Files favicon.ico>
ErrorDocument 404 "The requested file favicon.ico was not found.
</Files>

DirectoryIndex index.php

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A1209600
<FilesMatch \.php$>
ExpiresActive Off
</FilesMatch>
<FilesMatch \.cgi$>
ExpiresActive Off
</FilesMatch>
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} !\.cgi$
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>

g1smd

7:44 pm on Nov 16, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



After Order allow,deny you need to add the right "allow from ..." or "deny from ..." rules.