2012-02-20 37 views
0

私のテーマには、指定されたパラメータに基づいて異なる表示をするカスタムページがあります。このページは、ウェブサイトのホームページとして設定されています。以下のような組み合わせが可能 有効なパラメータ:私は何をしようとしているWordPressの書き換えルール

my_domain/?fa={action}&type={type} 
my_domain/?fa={action}&id={type} 
my_domain/?fa={action} 

は、以下にこれらのリンクを変換することです:

my_domain/fa/{action}/type/{type} 
my_domain//fa/{action}/id/{type} 
my_domain/fa/{action} 

私の.htaccessファイルは次のようになりますが、それ

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteRule ^fa/(.*)/type/(.*)$ /index.php [L] 
RewriteRule ^fa/(.*)/id/(.*)$ /index.php?fa=$1&fid=$2 [L] 
RewriteRule ^fa/(.*)$ /index.php?fa=$1 [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

私はここで間違っていますか?

おかげで、 ラドゥ

答えて

1

同じ問題は、私がリンクを失った「カイルEジェンティーレ」により作成されたクラスを使用していました。

ですが、彼のクラスは以下のとおりです。 ファイルを作成します。私はそれはあなたの最初の二つの変数、FAのために働くだろう知っている ...

//------------------------------------------------- 
//ADDING REWRITE RULES AND QUERY VARS 
//------------------------------------------------- 
include('add_rewrite_rules.php'); 
$options = array(
     'query_vars' => array('fa', 'type'), 
     'rules' => 
      array(
       '(.+?)/([^/]+)/([^/]+)/?$' => 'index.php?pagename=$matches[1]&fa=$matches[2]&type=$matches[3]' 
      ) 
    ); 
$rewrite = new Add_rewrite_rules($options); 
add_action('wp_head', array(&$rewrite, 'flush_rules')); 
add_action('generate_rewrite_rules', array(&$rewrite, 'add_rewrite_rules')); 
add_filter('query_vars', array(&$rewrite, 'add_query_vars')); 
//------------------------------------------------- 
//ADDING REWRITE RULES AND QUERY VARS 
//------------------------------------------------- 

はに探して価値がある可能性があり、あなたのfuncitons.phpファイルで、その後add_rewrite_rules.php

//prevent duplicate loading of the class if you are using this in multiply plugins 
if(!class_exists('add_rewrite_rules')){ 

    class Add_rewrite_rules{ 

     var $query_vars; 
     var $rules; 

     function __construct($options){ 
      $this->init($options); 
     } 

     function init($options){ 
      foreach($options as $key => $value){ 
       $this->$key = $value; 
      } 
     } 

     function rules_exist(){ 
      global $wp_rewrite; 

      $has_rules = TRUE; 

      foreach($this->rules as $key => $value){ 
       if(!in_array($value, $wp_rewrite->rules)){ 
        $has_rules = FALSE; 
       } 
      } 

      return $has_rules; 
     } 

     //to be used add_action with the hook 'wp_head' 
     //flushing rewrite rules is labor intense so we better test to see if our rules exist first 
     //if the rules don't exist flush its like after a night of drinking 
     function flush_rules(){ 
      global $wp_rewrite; 

      if(!$this->rules_exist()){ 
       //echo "flushed"; // If want to see this in action uncomment this line and remove this text and you will see it flushed before your eyes 
       $wp_rewrite->flush_rules(); 
      } 
     } 

     //filter function to be used with add_filter() with the hook "query_vars" 
     function add_query_vars($query_vars){ 

      foreach($this->query_vars as $var){ 
       $query_vars[] = $var; 
      } 

      return $query_vars; 
     } 

     //to be used with a the add_action() with the hook "generate_rewrite_rules" 
     function add_rewrite_rules(){ 
      global $wp_rewrite; 

      $wp_rewrite->rules = $this->rules + $wp_rewrite->rules; 
     } 

    } 

} 

を&タイプしかし... 、あなたがIDを追加するために少しを再度書くことができるかどうかわからない

マーティ