1

私は現在、審美的な目的でパラメータを操作するためにこれが必要なプロジェクトに取り組んでいます。

add_rewrite_rule( '([^/]*)/user/([^/]+)','index.php?pagename=$matches[1]&username=$matches[2]', 'top' );
-> would correctly retrieve the userID (in this case 232) from the following URL: http://mysite.com/userlisting/user/232

add_rewrite_rule( '([^/]*)/([^/]*)/user/([^/]+)','index.php?pagename=$matches[1]&username=$matches[2]', 'top' );
-> would correctly retrieve the userID (in this case 232) from the following URL: http://mysite.com/parent_directory/userlisting/user/232

これで、たとえばこれらのルールを10個追加して、少なくとも10レベルの階層を確実に実行できますが、現在の「ユーザーリスト」のレベル数に基づいて、ある程度動的にすることができます。

どんな助けでも大歓迎です。

4

1 に答える 1

0
 add_rewrite_rule( '([^/]*)/([^/]*)/user/([^/]+)','index.php?pagename=$matches[1]&username=$matches[2]', 'top' );
 -> would correctly retrieve the userID (in this case 232) from the following URL: http://mysite.com/parent_directory/userlisting/user/232

いいえ、そうではありません。

  • $matches[1]はparent_directory
  • $matches[2]はuserlisting
  • $ matches [3]は232(つまりuserID)になります

したがって、内部URLはindex.php?pagename = parent_directory&username=userlistingになります。


実際には、問題を解決することは、複数のレベルをどのように処理したいかによって異なります。つまり、それらがphpにどのように渡されるか、1つの可能性は次のようになります。

add_rewrite_rule( '(.+?)/user/([^/]+)','index.php?pagename=$matches[1]&username=$matches[2]', 'top' );

この場合、

index.php?pagename = parent_directory / userlisting&username = 232

つまり、URLに存在するのと同じ数のディレクトリが「ページ名」になります。ディレクトリ名の一部である/から除外しないでください。

ただし、さまざまな階層レベルをPHPに異なる方法で表示する場合は、異なる方法で行うことができます。

于 2013-03-26T14:02:58.407 に答える