I have a wordpress page named: directory (it uses a custom template).
When I call the page with:
http://localhost:8888/wordpress/directory/?segments=listings/list
It gives me the results I need. Now I need to make the url cleaner so that it will look like:
http://localhost:8888/wordpress/directory/listings/list
I tried this .htaccess with no luck (I get an internal server error):
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteRule ^directory/?(.*) /wordpress/directory/?segments=$1 [QSA, L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
Any ideas how I could get this to work?
EDIT:
Oops, looking more closely at the WP Rewrite Class page noted by Dwayne, I see that the specific example they provided was exactly what I needed. The code was provided on that page after:
A Quick and dirty example for rewriting…
add_filter( 'rewrite_rules_array','my_insert_rewrite_rules' );
add_filter( 'query_vars','my_insert_query_vars' );
add_action( 'wp_loaded','my_flush_rules' );
// flush_rules() if our rules are not yet included
function my_flush_rules(){
$rules = get_option( 'rewrite_rules' );
if ( ! isset( $rules['(project)/(\d*)$'] ) ) {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
}
// Adding a new rule
function my_insert_rewrite_rules( $rules )
{
$newrules = array();
$newrules['(project)/(\d*)$'] = 'index.php?pagename=$matches[1]&id=$matches[2]';
return $newrules + $rules;
}
// Adding the id var so that WP recognizes it
function my_insert_query_vars( $vars )
{
array_push($vars, 'id');
return $vars;
}
I just substituted ‘directory’ for ‘project’ and ‘segments’ for ‘id’ in the example code , and used ‘(directory)/(.*)$’ for the rule to match. I put that in my plugin and it worked just fine.
Thanks for the help.