Support » Fixing WordPress » How to redirect /page/subpage to a template file?

  • I have a page called “courses”, which uses a template file for this page.
    The slug is courses.

    But, when I try to access I get an 404 error. Is there any way to make this page call the template file set for courses? without making changes in 404.php or creating new subpages thru the admin panel.

    Thank you!

Viewing 1 replies (of 1 total)
  • I found a way to do this:

    function courses_rewrite_rules($wp_rewrite) {
    	$new_rules = array(
    		'courses/(.*)' => 'index.php?page_id=34'
    	$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
    function courses_flush_rules() {
    	global $wp_rewrite;
    add_action('init', 'courses_flush_rules');
    add_action('generate_rewrite_rules', 'courses_rewrite_rules');

    This piece of code does what I want. But everytime a wordpress page (not necessarily /courses ) is requested it delete and re-create the rewrite rules on the database, even if theres no change. I think this can cause some problem in the future.


    function courses_set_rule() {
    add_rewrite_rule(‘courses/(.*)’, ‘index.php?page_id=34’, ‘top’);
    add_action(‘init’, ‘courses_set_rule’);

Viewing 1 replies (of 1 total)
  • The topic ‘How to redirect /page/subpage to a template file?’ is closed to new replies.