I am rebuilding a static website for a client using Wordpress on the main domain- eg domain.com. There is also a directory of members website at directory.domain.com which I was hoping to migrate over to the main website- domain.com/directory/ (We want to do this, firstly to keep it on the same domain, but also so that we may be able to use the same layout and styles- preferably by using a page template.)

The app has a main page, a list view and a member details view, and search queries are sent using $_GET. URLs are made to look nice (semantic URLs) by using mod_rewrite eg: directory.domain.com/list/people/all/by-name/page-1/20-per-page/

example code from the .htaccess file could be:

RewriteRule ^list/([a-zA-Z0-9-\-]+)/([a-zA-Z0-9-\-]+)/([a-zA-Z0-9-\-]+)/$ /list.html?member-type=$1&area-name=$2&order-by=$3 [L]

I've thought of two possibilities in which to achieve the above...

1) If we kept the directory of members on the different subdomain then it might be possible to cache and use a copy of a blank page on the WP site and then use this as a template for the directory of members.

2) Somehow have the php code of the directory of members within a WP page.

Ideally I want to go for (2), but I am not sure how to implement this.

So what's the best way to achieve this? Specifically...

  • How do I run the PHP for the app within a WP page?
  • How do I access the $_GET variables and enable nice (semantic) urls using mod_rewrite? For example, if the directory is on domain.com/directory/ how do I get it to pass $_GET variables by extending the url but keeping the same WP page, eg. domain.com/directory/list/people/all/by-name/page-1/20-per-page/ ?

Sorry if I haven't explained this very well, it's a little complicated!

2 Answers 2


Its not good way to edit .htaccess for wordpress url rewriting (only for main urls settings from admin panel)

You found your response here : API basic url rewriting or The Rewrite API: Post Types & Taxonomies

An example :

add_action( 'init', 'rewrite_rule' );
function rewrite_rule()


  // Remember to flush the rules once manually after you added this code!
      // The regex to match the incoming URL
      // The resulting internal URL: `index.php` because we still use WordPress
      // `pagename` because we use this WordPress page
      // `designer_slug` because we assign the first captured regex part to this variable
      // This is a rather specific URL, so we add it to the top of the list
      // Otherwise, the "catch-all" rules at the bottom (for pages and attachments) will "win"
      'top' );

add_filter( 'query_vars', 'query_vars' );
function query_vars( $query_vars )
  $query_vars['yp'] = 'your_param';
  return $query_vars;

You get data : $param_website_name = $wp->query_vars['your_param'];

i hope that help you ;)

  • At first glance I thought "oh no!" too complicated, but I have had a quick try and it works really well! Thanks so much. What's the best way to update content in the <head> such as the <title> tag? I suppose I could add some custom php to the header.php file. I need to set up 7 rewrite rules (there are up to 7 fields in the url), what's the best way to achieve this? I noticed something about endpoints in the article you linked to, but don't understand it. Again, thanks so much for your help.
    – baritoneuk
    Jun 12, 2012 at 10:42
  • 1
    Do not flush the rewrite rules on init! This should happen just once, not on every request.
    – fuxia
    Jun 13, 2012 at 6:01
  • @baritoneuk : For me to have multiple query and rewrite rule. I had on rewrite_rule an key for exemple : Jun 13, 2012 at 8:58
  • @toscho can you clarify what you mean? Is the above ok?
    – baritoneuk
    Jun 15, 2012 at 17:01
  • @baritoneuk No, flush the rules on activation only – or manually. init fires on every request, and the rewrite rule flush is an expensive write action to database.
    – fuxia
    Jun 15, 2012 at 17:02

@baritoneuk : For me to have multiple query and rewrite rule. I had on rewrite_rule an key for exemple : add_rewrite_rule( // The regex to match the incoming URL 'yourpage/makey-([a-z0-9-]+)/?', 'index.php?pagename=yourpage&your_param=$matches[1]', 'top' );

And in my link LINK with this way, i can has multiple rewrite rule with same redirection and same pattern ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.