Files
bedrock/lib/rewrites.php
Ben Word fea92a61aa Rewrites organization
- Create lib/rewrites.php and move everything from lib/htaccess.php
except the H5BP htaccess functionality into it

- In the config, change add_theme_support('rewrite-urls') to
add_theme_support('rewrites')

- Remove the Apache/LightSpeed HTTPD check for rewrites

- Update docs with better Nginx rewrite rules
2013-02-04 19:56:42 -06:00

57 lines
1.7 KiB
PHP

<?php
/**
* URL rewriting
*
* Rewrites currently do not happen for child themes (or network installs)
* @todo https://github.com/retlehs/roots/issues/461
*
* Rewrite:
* /wp-content/themes/themename/css/ to /css/
* /wp-content/themes/themename/js/ to /js/
* /wp-content/themes/themename/img/ to /img/
* /wp-content/plugins/ to /plugins/
*
* If you aren't using Apache, alternate configuration settings can be found in the docs.
*
* @link https://github.com/retlehs/roots/blob/master/doc/rewrites.md
*/
function roots_add_rewrites($content) {
global $wp_rewrite;
$roots_new_non_wp_rules = array(
'assets/css/(.*)' => THEME_PATH . '/assets/css/$1',
'assets/js/(.*)' => THEME_PATH . '/assets/js/$1',
'assets/img/(.*)' => THEME_PATH . '/assets/img/$1',
'plugins/(.*)' => RELATIVE_PLUGIN_PATH . '/$1'
);
$wp_rewrite->non_wp_rules = array_merge($wp_rewrite->non_wp_rules, $roots_new_non_wp_rules);
return $content;
}
function roots_clean_urls($content) {
if (strpos($content, FULL_RELATIVE_PLUGIN_PATH) === 0) {
return str_replace(FULL_RELATIVE_PLUGIN_PATH, WP_BASE . '/plugins', $content);
} else {
return str_replace('/' . THEME_PATH, '', $content);
}
}
if (!is_multisite() && !is_child_theme() && get_option('permalink_structure')) {
if (current_theme_supports('rewrites')) {
add_action('generate_rewrite_rules', 'roots_add_rewrites');
}
if (!is_admin() && current_theme_supports('rewrites')) {
$tags = array(
'plugins_url',
'bloginfo',
'stylesheet_directory_uri',
'template_directory_uri',
'script_loader_src',
'style_loader_src'
);
add_filters($tags, 'roots_clean_urls');
}
}