Wrap rewrite rules in IfModule. Bug 318.

git-svn-id: http://svn.automattic.com/wordpress/trunk@1721 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
rboren 2004-09-28 17:55:52 +00:00
parent 71ee7bb747
commit f16701674d
1 changed files with 23 additions and 21 deletions

View File

@ -1420,31 +1420,33 @@ function rewrite_rules($matches = '', $permalink_structure = '') {
} }
function mod_rewrite_rules ($permalink_structure) { function mod_rewrite_rules ($permalink_structure) {
$site_root = str_replace('http://', '', trim(get_settings('siteurl'))); $site_root = str_replace('http://', '', trim(get_settings('siteurl')));
$site_root = preg_replace('|([^/]*)(.*)|i', '$2', $site_root); $site_root = preg_replace('|([^/]*)(.*)|i', '$2', $site_root);
if ('/' != substr($site_root, -1)) $site_root = $site_root . '/'; if ('/' != substr($site_root, -1)) $site_root = $site_root . '/';
$home_root = str_replace('http://', '', trim(get_settings('home'))); $home_root = str_replace('http://', '', trim(get_settings('home')));
$home_root = preg_replace('|([^/]*)(.*)|i', '$2', $home_root); $home_root = preg_replace('|([^/]*)(.*)|i', '$2', $home_root);
if ('/' != substr($home_root, -1)) $home_root = $home_root . '/'; if ('/' != substr($home_root, -1)) $home_root = $home_root . '/';
$rules = "RewriteEngine On\n"; $rules = "<IfModule mod_rewrite.c>\n";
$rules .= "RewriteBase $home_root\n"; $rules .= "RewriteEngine On\n";
$rewrite = rewrite_rules('', $permalink_structure); $rules .= "RewriteBase $home_root\n";
foreach ($rewrite as $match => $query) { $rewrite = rewrite_rules('', $permalink_structure);
// Apache 1.3 does not support the reluctant (non-greedy) modifier. foreach ($rewrite as $match => $query) {
$match = str_replace('.+?', '.+', $match); // Apache 1.3 does not support the reluctant (non-greedy) modifier.
$match = str_replace('.+?', '.+', $match);
if (strstr($query, 'index.php')) { if (strstr($query, 'index.php')) {
$rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA]\n"; $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA]\n";
} else { } else {
$rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA]\n"; $rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA]\n";
} }
} }
$rules .= "</IfModule>\n";
$rules = apply_filters('rewrite_rules', $rules); $rules = apply_filters('rewrite_rules', $rules);
return $rules; return $rules;
} }
function get_posts($args) { function get_posts($args) {