Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Peter Cooperx http://www.petercooper.co.uk/

« Newer Snippets
Older Snippets »
Showing 1-7 of 7 total  RSS 

Multiple sites on Apache without virtual hosts

Being forced to work on a Windows based Apache, but came up with this nice way to access a bunch of multiple sites on the same Apache through one IP (no vhosts were allowed) with a URL trick:

   1  AliasMatch ^/_(.+?)/(.*)?$ "d:/sites/$1/$2"
   2  
   3  <Directory "d:/sites/*">
   4  	Options Indexes
   5  	AllowOverride All
   6  	Order allow,deny
   7  	Allow from all
   8  </Directory>

Making symbolic linked Rails apps work when folder accessed with no trailing slash

Snippets is at bigbold.com/snippets/ but bigbold.com/snippets always failed with "Bad Request". bigbold.com/snippets always seemed to rewrite into 'snippets.html' for some reason, so this change to .htaccess cures it:

   1  RewriteCond %{REQUEST_FILENAME} !-f
   2  RewriteCond %{REQUEST_FILENAME} !snippets\.html
   3  RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
   4  RewriteRule snippets\.html /snippets/ [R]


Replace snippets with the name of your own folder, obviously.

Parse HTML files as PHP

Add this to your .htaccess file in Apache:

   1  AddType application/x-httpd-php .html

FastCGI test script

If you're having trouble with FastCGI (as I was), this Perl script can help you see if the problem is at the Apache end or the app end. In my case I'd simply not deleted the old Ruby sessions for my Rails app when switching from CGI to FCGI ;-) This script proved my Apache wasn't broken, at least.

   1  #!/usr/bin/perl
   2  
   3  use FCGI;
   4  
   5  $cnt = 0;
   6  
   7  while (FCGI::accept() >= 0)
   8  {
   9     print ("Content-type: text/html\r\n\r\n");
  10     print ("<head>\n<title>FastCGI Demo Page (perl)</title>\n</head>\n");
  11     print  ("<h1>FastCGI Demo Page (perl)</h1>\n");
  12     print ("This is coming from a FastCGI server.\n<BR>\n");
  13     print ("Running on <EM>$ENV{USER}</EM> to <EM>$ENV{REMOTE_HOST}</EM>\n<BR>\n");
  14      $cnt++;
  15     print ("This is connection number $cnt\n");
  16  }

Block Google Web Accelerator with .htaccess and mod_rewrite

By Shane Allen.

   1  RewriteEngine On
   2  RewriteCond %{HTTP_X_MOZ} ^prefetch$
   3  RewriteRule ^.*$ - [F]

Prevent yourself from getting Slashdotted

Assuming you have mod_rewrite and AllowOverride activated, throw this in the .htaccess file for the directory you don't want to be Slashdotted:

   1  RewriteEngine On
   2  RewriteCond %{HTTP_REFERER} ^.*slashdot.*$
   3  RewriteRule .* - [F]


This all assumes the editors actually check the links before posting the story, but this should reasonably mean no-one on Slashdot can link to you, even if it's a bit over the top.

Adding DSO modules to Apache 2.0.53 on UNIX

For some reason all the Apache docs tell you to run apxs over a .so file. I never had any .so files, but I found this to work (if you have the .c file for your module).

   1  /usr/local/apache2/bin/apxs -c mod_foo.c
   2  /usr/local/apache2/bin/apxs -i -a -n foo mod_foo.la

It seems that the apxs compilation process puts the .so file in a folder called .libs/ which is invisible to a regular ls, but the above works too.
« Newer Snippets
Older Snippets »
Showing 1-7 of 7 total  RSS