• Hi,

    i’ve created acustom PostType and would like to achieve the following goal:

    /ctype/postname/

    There are links which looks like the following, but for this link there exists no post / page.

    /ctype/postname/unique-id/

    I thought I could redirect it in the .htaccess to an existing post, which then delivers me all formation by the “unique-id”

    RewriteRule ^ctype/(.*)/(.*)/$ index.php/?p=100&cid=$2&name=$1 [L]

    I also tried it with a WP rewrite rule, unfortunately without success.

    add_rewrite_rule( 'ctype/([^/]+)/([^/]+)', 'index.php/?p=100&cid=$matches[2]&name=$matches[2]', 'top' );

    Has anyone here a tip or is it completely the wrong approach?

    Many Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    If no post exists for postname, then do not pass that value as “name” because it will conflict with p=100. Is this post ID 100 supposed to handle the cid value and do something meaningful? If this page also needs a “name” value, use a label that is not used by WP_Query, like “pname”.

    In the WP rewrite rule, I believe you want pname=$matches[1]. Note the 1, not 2. Also be sure to flush the rewrite rules anytime you add or change a rule. You can just go to the permalink settings page and click the Save Changes button. No need to actually change anything.

    Thread Starter ssurfer

    (@ssurfer)

    Hi,

    /ctype/postname/unique-id/ doesn’t exists.
    And the page with id 100 exists and and will display all the information wich belongs to the value of cid-parameter

    Thread Starter ssurfer

    (@ssurfer)

    After flushing the rewrite rules it’s working.

    Thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Rewrite Rule for Custom Post Type’ is closed to new replies.