Search code examples
apache.htaccessvirtualhostfastcgi

Virtual host setup < cgi script


The issue

I'm writing a cgi script in c++. All works well as long as I go in to the precise url: http://localhost:90/joppli.bot

Now I'm trying to make a simple redirect to from everything to my cgi script. eg:

http://localhost:90/
http://localhost:90/foo
http://localhost:90/foo/bar

...should all render the same content as entering http://localhost:90/joppli.bot


Files

.htaccess

RewriteEngine On

RewriteRule (.+)/$ /$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ joppli.bot [NC,L]

virtual host

<VirtualHost *:90>
    DocumentRoot /var/www/joppli-bot
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so
    SetHandler fastcgi-script
    
    <Directory "/var/www/joppli-bot">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /var/www/joppli-bot/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/www/joppli-bot/log/apache2/access.log combined
</VirtualHost>

files at /var/www/joppli-bot

.htaccess
joppli.bot -> /home/erik/NetBeansProjects/joppli.bot/dist/Debug/GNU-Linux-x86/joppli.bot
log
+ apache2
  + access.log
  + error.log

Solution

  • Thanks to Justin Iurman Who wrote the following as a comment, witch solved most of it:

    In <Directory "/var/www/joppli-bot"> block, replace AllowOverride None by AllowOverride All (otherwise your htaccess is disabled)

    I also added DirectoryIndex joppli.bot at the bottom of my .htaccess file to route all trafic from root directory to the script as well..