Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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()
{

  global
  $wp,$wp_rewrite;

  // Remember to flush the rules once manually after you added this code!
  add_rewrite_rule(
      // The regex to match the incoming URL
      'yourpage/([a-z0-9-]+)/?',
      // 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
      'index.php?pagename=yourpage&your_param=$matches[1]',
      // 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' );
  $wp_rewrite->flush_rules();
}

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 ;)

share|improve this answer
    
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 '12 at 10:42
1  
Do not flush the rewrite rules on init! This should happen just once, not on every request. –  toscho Jun 13 '12 at 6:01
    
@baritoneuk : For me to have multiple query and rewrite rule. I had on rewrite_rule an key for exemple : –  Mepps Jun 13 '12 at 8:58
    
@toscho can you clarify what you mean? Is the above ok? –  baritoneuk Jun 15 '12 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. –  toscho Jun 15 '12 at 17:02
show 1 more comment

@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 ;)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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