Write rewrite rules to .htacces if .htaccess is writable. Create .htaccess if it does not exist and the directory is writable. Props to Owen Winkler.

git-svn-id: https://develop.svn.wordpress.org/trunk@1489 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2004-07-27 23:37:45 +00:00
parent 5cf4b39065
commit 483dfd5388
3 changed files with 105 additions and 26 deletions

View File

@@ -1352,6 +1352,31 @@ function rewrite_rules($matches = '', $permalink_structure = '') {
return $rewrite;
}
function mod_rewrite_rules ($permalink_structure) {
$site_root = str_replace('http://', '', trim(get_settings('siteurl')));
$site_root = preg_replace('|([^/]*)(.*)|i', '$2', $site_root);
if ('/' != substr($site_root, -1)) $site_root = $site_root . '/';
$home_root = str_replace('http://', '', trim(get_settings('home')));
$home_root = preg_replace('|([^/]*)(.*)|i', '$2', $home_root);
if ('/' != substr($home_root, -1)) $home_root = $home_root . '/';
$rules = "RewriteEngine On\n";
$rules .= "RewriteBase $home_root\n";
$rewrite = rewrite_rules('', $permalink_structure);
foreach ($rewrite as $match => $query) {
if (strstr($query, 'index.php')) {
$rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA]\n";
} else {
$rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA]\n";
}
}
$rules = apply_filters('rewrite_rules', $rules);
return $rules;
}
function get_posts($args) {
global $wpdb;
parse_str($args, $r);