B
B
BonBon Slick2017-02-23 19:37:42
Apache HTTP Server
BonBon Slick, 2017-02-23 19:37:42

How to add .html to the end of a link?

There is a site URL
1st https://my_site.com/remains as it is.
2nd level: https://my_site.com/my_second_page.html
3rd level and above:

https://my_site.com/my_second_page/my_third_page.html

Tried:
if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')){
    $wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';
 }
// некоторые ссылки тогда битые

All links are deeper than the 2nd level, add .html at the end of the url, how?
Most likely you need some kind of rule in htaccess. I have already tried everything in WP, including hooks, although I could be wrong.
This code only changes the URL of the product, but the category does not work for some reason:
// для продукта
function wpse_178112_permastruct_html( $post_type, $args ) {
    if ( $post_type === 'product' )
        add_permastruct( $post_type, "{$args->rewrite['slug']}/%$post_type%.html", $args->rewrite );
}
add_action( 'registered_post_type', 'wpse_178112_permastruct_html', 10, 2 );
// для категории, когда идем на страницу категории там ОШИБКА 404
function wpse_178112_category_permastruct_html( $taxonomy, $object_type, $args ) {
    if ( $taxonomy === 'product_cat' )
        add_permastruct( $taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%.html", $args['rewrite'] );
}
add_action( 'registered_taxonomy', 'wpse_178112_category_permastruct_html', 10, 3 );

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dark19, 2017-02-23
@BonBonSlick

If I understand the question correctly, then you need to put something like this in the settings (Settings->Permalinks->Custom Structure): https://site_name/%postname%.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question