Make WordPress Core


Ignore:
Timestamp:
07/27/2004 11:37:45 PM (20 years ago)
Author:
rboren
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/options-permalink.php

    r1438 r1489  
    4545<div class="updated"><p><?php _e('Permalink structure updated.'); ?></p></div>
    4646<?php endif; ?>
     47
     48<?php if(isset($_POST['rules'])) {
     49        $rules = explode("\n", $_POST['rules']);
     50        if(insert_with_markers(ABSPATH.'.htaccess', 'WordPress', $rules)) {
     51?>
     52<div class="updated" id="htupdate"><p><?php _e('mod_rewrite rules written to .htaccess.'); ?></p></div>
     53<?php
     54        } else {
     55?>
     56<div class="updated" id="htupdate"><p><?php _e('Failed to write mod_rewrite rules to .htaccess.'); ?></p></div>
     57<?php
     58        }
     59    }
     60?>
     61
    4762<div class="wrap">
    4863  <h2><?php _e('Edit Permalink Structure') ?></h2>
     
    108123?>
    109124  <p><?php printf(__('Using the permalink structure value you currently have, <code>%s</code>, these are the mod_rewrite rules you should have in your <code>.htaccess</code> file. Click in the field and press <kbd>CTRL + a</kbd> to select all.'), $permalink_structure) ?></p>
    110   <?php
    111 $site_root = str_replace('http://', '', trim(get_settings('siteurl')));
    112 $site_root = preg_replace('|([^/]*)(.*)|i', '$2', $site_root);
    113 if ('/' != substr($site_root, -1)) $site_root = $site_root . '/';
    114 
    115 $home_root = str_replace('http://', '', trim(get_settings('home')));
    116 $home_root = preg_replace('|([^/]*)(.*)|i', '$2', $home_root);
    117 if ('/' != substr($home_root, -1)) $home_root = $home_root . '/';
    118 
    119 ?>
    120 <form action="">
     125<form action="options-permalink.php" method="post">
    121126    <p>
    122         <textarea rows="5" style="width: 98%;">RewriteEngine On
    123 RewriteBase <?php echo $home_root; ?>
    124 <?php
    125 $rewrite = rewrite_rules('', $permalink_structure);
    126 $rules = '';
    127 foreach ($rewrite as $match => $query) {
    128     if (strstr($query, 'index.php')) {
    129         $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA]\n";
    130     } else {
    131         $rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA]\n";
    132     }
    133 }
    134 echo apply_filters('rewrite_rules', $rules);
    135 ?>
     127<textarea rows="5" style="width: 98%;" name="rules"><?php echo mod_rewrite_rules($permalink_structure); ?>
    136128</textarea>
    137129    </p>
    138     <?php printf(__('<p>If your <code>.htaccess</code> file is writable by WordPress, you can <a href="%s">edit it through your template interface</a>.</p>'), 'templates.php?file=.htaccess') ?>
     130<?php
     131if ((! file_exists(ABSPATH.'.htaccess') && is_writable(ABSPATH)) || is_writable(ABSPATH.'.htaccess')) {
     132?>
     133    <p class="submit">
     134        <input type="submit" name="writerules" value="<?php _e('Write mod_rewrite rules to .htaccess &raquo;') ?>">
     135    </p>
     136<?php } ?>
    139137</form>
    140138 
Note: See TracChangeset for help on using the changeset viewer.