diff --git a/.htaccess b/.htaccess
index 196e613a7..5671d98ba 100644
--- a/.htaccess
+++ b/.htaccess
@@ -42,6 +42,7 @@ RewriteRule ^~~([^/]*)/?$ /~~$1/lobby [R=301,L]
RewriteRule ^~~([^/]*)/(teambuilder|ladder|lobby|battle)/?$ index.php?server=$1 [L,QSA]
RewriteRule ^~~([^/]*)/(lobby|battle)-([A-Za-z0-9-]*)$ index.php?server=$1 [L,QSA]
RewriteRule ^~~([^:/]*)(:[0-9]*)?/action\.php$ action.php?serverid=$1 [L,QSA]
+RewriteRule ^style/custom/([A-Za-z0-9-]*)\.css$ customcss.php?server=$1 [L]
RewriteRule ^backup/ - [F]
RewriteRule ^\.git/ - [F]
diff --git a/customcss.php b/customcss.php
new file mode 100644
index 000000000..0f7cfccf8
--- /dev/null
+++ b/customcss.php
@@ -0,0 +1,58 @@
+set('Filter.ExtractStyleBlocks', TRUE);
+ $purifier = new HTMLPurifier($config);
+ $level = error_reporting(E_ALL & ~E_STRICT);
+ $html = $purifier->purify('');
+ error_reporting($level);
+ list($outputcss) = $purifier->context->get('StyleBlocks');
+ file_put_contents($cssfile, $outputcss);
+ echo $outputcss;
+ } else {
+ // Error condition - clear the cached file.
+ file_put_contents($cssfile, '');
+ }
+}
+curl_close($curl);
+
diff --git a/index.php.template.txt b/index.php.template.txt
index 150178960..19f8a363e 100644
--- a/index.php.template.txt
+++ b/index.php.template.txt
@@ -107,7 +107,7 @@ if (!$challengeresponse) {
-
+