$mtime_htaccess) { $no_changes_needed = false; break; } } if ($no_changes_needed) { throw new XHTMLCompiler_Exception(503, false, 'No changes detected in xhtml-compiler/config.php, xhtml-compiler/config.default.php or xhtml-compiler/htaccess.php.'); } if (!file_exists('.htaccess.in')) { $contents = file_get_contents('.htaccess'); } else { $contents = file_get_contents('.htaccess.in'); } // do writeability check if ( ( strpos($contents, $identifier_begin) === false || strpos($contents, $identifier_end) === false ) && strpos($contents, $identifier_here) === false ) { throw new XHTMLCompiler_Exception(503, false, 'Pre-existing htaccess not configured to accept new rules'); } // replace old rules with new set $regex = '/' . preg_quote($identifier_begin, '/') . '.+?' . preg_quote($identifier_end, '/') . '/s'; $contents = preg_replace($regex, $identifier_here, $contents); } else { $contents = $identifier_here; } // build the new htaccess $new_contents = array(); $new_contents[] = $identifier_begin; $new_contents[] = 'RewriteEngine on'; $new_contents[] = 'RewriteBase ' . $xc->getConf('web_path') . '/'; // create permanent redirects if (file_exists('redirects.txt')) { $redirects = explode("\n", file_get_contents('redirects.txt')); foreach ($redirects as $redirect) { $redirect = trim($redirect) . ' '; if ($redirect === ' ') continue; if ($redirect[0] === '#') continue; list($src, $dest, $p) = explode(' ', $redirect); if ($p !== '[P]') $src = '^' . preg_quote($src) . '$'; // We use rewrite to prevent the appending of ?f= querystring $new_contents[] = 'RewriteRule ' . $src . ' ' . $dest . ' [R=permanent,L]'; } } $big_exp = array(); $directory_index = $xc->getConf('directory_index'); $indexed_dirs = $xc->getConf('indexed_dirs'); $allowed_dirs = $xc->getConf('allowed_dirs'); foreach ($allowed_dirs as $dir => $recursive) { $r = ''; if ($recursive) { $r = "([^/]+/)*"; // escaped slashes not necessary } $len = strlen($dir); $slash = (!$len || $dir[$len-1] === '/') ? '' : '/'; $dir_exp = preg_quote($dir) . $slash . $r; if (is_array($indexed_dirs)) { $intercept = isset($indexed_dirs[$dir]) ? $indexed_dirs[$dir] : true; } else { $intercept = $indexed_dirs; } if (is_string($directory_index) && $intercept) { // setup index rewrite $new_contents[] = "RewriteRule ^($dir_exp)$ \$1$directory_index"; } $big_exp[] = $dir_exp; } $full_dir_exp = implode('|', $big_exp); $new_contents[] = 'RewriteCond %{REQUEST_FILENAME} !-f [OR]'; $new_contents[] = 'RewriteCond %{QUERY_STRING} purge=1 [OR]'; $new_contents[] = 'RewriteCond %{HTTP_COOKIE} purgatory=1'; $new_contents[] = "RewriteRule ^(($full_dir_exp)[^/]+\.html)$ xhtml-compiler/main.php?f=\$1 [L,QSA]"; // if purge is set, also handle directories $new_contents[] = 'RewriteCond %{QUERY_STRING} purge=1'; $new_contents[] = "RewriteRule ^($full_dir_exp)$ xhtml-compiler/main.php?f=\$1 [L,QSA]"; // add application/xhtml+xml if the browser supports it $new_contents[] = 'RewriteCond %{HTTP_ACCEPT} application/xhtml\\+xml'; $new_contents[] = "RewriteRule ^(($full_dir_exp)[^/]+\.html)$ - \"[T=application/xhtml+xml,L]\""; // xc-deps are forbidden to outside world $new_contents[] = ''; $new_contents[] = ' Order allow,deny'; $new_contents[] = ' Deny from all'; $new_contents[] = ''; // errors.log is forbidden to outside world. In theory, this will occur only // in xhtml-compiler/, but it won't hurt to deny it everywhere. $new_contents[] = ''; $new_contents[] = ' Order allow,deny'; $new_contents[] = ' Deny from all'; $new_contents[] = ''; // setup RSS $new_contents[] = 'AddType application/rss+xml rss'; $new_contents[] = 'AddCharset UTF-8 .rss'; $new_contents[] = ''; $new_contents[] = ' '; $new_contents[] = ' Header append Cache-Control "no-cache, must-revalidate"'; $new_contents[] = ' '; $new_contents[] = ''; // set UTF-8 for HTML pages $new_contents[] = 'AddCharset UTF-8 .html'; $new_contents[] = $identifier_end; $contents = str_replace($identifier_here, implode($new_contents, PHP_EOL), $contents); file_put_contents('.htaccess', $contents); chmod('.htaccess', 0644); ?>

200: Okay

New .htaccess file successfully written