SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard drhowarddrfine's Avatar
    Join Date
    Aug 2005
    Posts
    3,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    cgi rewrite problems

    I've been using lighttpd for years but now I have to get a site working on Apache and can't quite get there. I have an executable web app, written in C (no scripts involved), that handles all page creation but not images, pdfs, etc. which just get served by their regular mime-type.

    So this web app works just fine and has for a year now. Going to mysite.com/page1/stuff gives you that page entirely generated by the web app.

    In Apache, I'm not entirely sure I need mod_rewrite to do this or whether it can/should be done with Alias or ScriptAlias. I've read rewrite will slow things down and I should use one of the Aliases if I can.

    I've gone through so many variations of htaccess that I've gotten to the point where I've forgotten what worked how and what didn't. I'm also not sure I'm putting the app in the right directory (Linux based). I've tried in cgi-bin but also public_html. I'm also not sure where the htaccess file should go or if I might need more than one.

    This is what I put in the root (public_html):
    RewriteEngine on
    RewriteCond %{REQUEST_URI} ! \.(js|css|[jm]pe?g|gif|png|tiff?|ico)$
    RewriteRule ^(.*) test [L]

    I get an error from the server saying the delimiters are wrong. If I comment that out, going to mysite.com gives me a popup asking me if I want to download a binary file. That file is my app so it's not executing it. I presume it's because I need ExecCGI somewhere.

    Or do I just need one of the Aliases?

    Despite a lot of reading and testing, I feel like a jumbled mess. Can someone clean me up, please?

  2. #2
    SitePoint Wizard drhowarddrfine's Avatar
    Join Date
    Aug 2005
    Posts
    3,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    After walking away from this for a while, I think what's confusing me is that the app is creating an error somehow. I'm getting a "premature ending of headers" error which usually indicates the HTTP headers are not being sent. But in my program, it's the first thing done and when I execute it from the command line, it's all there:
    Code:
    Content-type: text/html; charset=utf-8
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title>..........
    When I go to mypage.com/cgi-bin/test, I get a 500 internal server error and the error log gives the "premature" error mentioned above.

    So getting past this issue might be most of the battle.

    EDIT: I forgot to add that the only htaccess file I changed was the one in cgi-bin and it says "Options ExecCGI"

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    dhdf,

    Quite a bit there - especially for not saying which version of Apache and the physical location of your cgi-bin (it gets special treatment by Apache) and your TypeHandler for extensionless files.

    mod_alias, as part of the Apache core, is faster than mod_rewrite. A LIMITED amount of mod_rewrite code will not slow the service perceptibly (a lot of members show HUGE lists of mod_rewrite code which should be put into a RewriteMap - created only via httpd.conf).

    cgi-bin's special handling means that it is normally OUTSIDE the webspace and is not subject of .htaccess directives.

    The AddHandler statement should be within httpd.conf but can be in your .htaccess if necessary.
    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_URI} ! \.(js|css|[jm]pe?g|gif|png|tiff?|ico)$
    RewriteRule ^(.*) test [L]
    Nothing wrong with that (except for my abhorrence for (.*) - but it may actually be appropriate in this instance).
    Quote Originally Posted by dhdf
    I get an error from the server saying the delimiters are wrong. If I comment that out, going to mysite.com gives me a popup asking me if I want to download a binary file. That file is my app so it's not executing it. I presume it's because I need ExecCGI somewhere.
    That's a sign that the proper handler is not being used.

    Not sure that I've helped but you should get turned in the right direction.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  4. #4
    SitePoint Wizard drhowarddrfine's Avatar
    Join Date
    Aug 2005
    Posts
    3,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's on a shared host so I don't have access to httpd.conf Version 1.3

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    dhdf,

    On the assumption that you do have access to your cgi-bin, it's GOT to be in your directory but NOT in your webspace (public_html) and the same rule about .htaccess NOT applying to cgi-bin still applies. Ditto the AddHandler for the extensionless files (test).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  6. #6
    SitePoint Wizard drhowarddrfine's Avatar
    Join Date
    Aug 2005
    Posts
    3,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It turns out to be more complicated than all that. I compile the app on FreeBSD but it calls libraries that aren't available on Linux and the host is on a Linux system. So I have to find a way to make the app more standalone.

    Thanks for looking at all this.
    Doc


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •