Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Need to exclude a page from .shtml rewrite WordPress

I have imported .html files to my wordpress site and used the below code to rewrite the pages to have .html extension.

// Rewrite WordPress URLs to include .html endings

add_action('init', 'html_page_permalink', -1);

function html_page_permalink() {

global $wp_rewrite;

if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')){

$wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';

}

}

add_filter('user_trailingslashit', 'no_page_slash',66,2);

function no_page_slash($string, $type){

global $wp_rewrite;

if ($wp_rewrite->using_permalinks() && $wp_rewrite->use_trailing_slashes==true && $type == 'page'){

return untrailingslashit($string);

}else{

return $string;

}

}





The problem is I need to exclude certain pages from having the .html extension. I got this code from [[LINK href="http://wpquestions.com/question/show/id/7082"]]here[[/LINK]] and modified it but its not working



// Exclude pages from .hmtl rewrites

function my_insert_rewrite_rules( $rules ) {

$newrules = array();

$newrules['^blog$'] = 'index.php?post_type=post';
$newrules['^about$'] = 'index.php?post_type=post';
$newrules['^contact$'] = 'index.php?post_type=post';


return $newrules + $rules;

}

add_filter('rewrite_rules_array','my_insert_rewrite_rules');


How do I exclude certain pages from rewrite?

Answers (3)

2012-10-13

Arnav Joy answers:

try this and then resave permalink structure



function my_insert_rewrite_rules( $rules ) {



$newrules = array();



$newrules['^blog$'] = 'index.php?post_type=post';

$newrules['^about$'] = 'index.php?post_type=page';

$newrules['^contact$'] = 'index.php?post_type=page';





return $newrules + $rules;



}



add_filter('rewrite_rules_array','my_insert_rewrite_rules');


safiweb comments:

I just tried the above but still doesn't work.

2012-10-13

John Cotton answers:

Instead of changing all permalinks, you can use the post_type_link filter to modify the link for individual pages. There's a good discussion about it here: [[LINK href="http://xplus3.net/2010/05/20/wp3-custom-post-type-permalinks/"]]http://xplus3.net/2010/05/20/wp3-custom-post-type-permalinks/[[/LINK]] but if you search through previous questions, you will find some similar answers with code.

2012-10-14

Dbranes answers:

You can use the plugin

http://wordpress.org/extend/plugins/custom-permalinks/

<blockquote>Lay out your site the way you want it. Set the URL of any post, page, tag or category to anything you want. Old permalinks will redirect properly to the new address. Custom Permalinks gives you ultimate control over your site structure.
</blockquote>

This plugin can overwrite the global <strong>.html</strong> page structure you have for individual posts/pages.

It uses the <strong>template_redirect</strong> hook to achieve this and post_link/page_link filters to take care of the links.

So you could use it to change

blog.html => blog
about.html => about
contact.html => contact