From a8ac98ae00704499951eeccbf73b826a4263eaf4 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 21 Mar 2008 01:10:42 +0000 Subject: [PATCH] Add redirect support. git-svn-id: http://htmlpurifier.org/svnroot@1614 48356398-32a2-884e-a903-53898d9a118a --- htaccess.php | 13 +++++++++++++ main.php | 2 -- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/htaccess.php b/htaccess.php index b83738d..828888f 100644 --- a/htaccess.php +++ b/htaccess.php @@ -25,6 +25,7 @@ if (file_exists('.htaccess')) { 'xhtml-compiler/config.default.php', 'xhtml-compiler/config.smoketest.php', 'xhtml-compiler/htaccess.php', + 'redirects.txt', ); $mtime_htaccess = filemtime('.htaccess'); @@ -82,6 +83,18 @@ $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) . ' '; + 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'); diff --git a/main.php b/main.php index af3a087..4fcb76c 100644 --- a/main.php +++ b/main.php @@ -15,5 +15,3 @@ $page = normalize_index($page, $xc->getConf('directory_index')); $page = new XHTMLCompiler_Page($page); $page->display(); - -?> \ No newline at end of file -- 2.11.4.GIT