• Hello,

    I’ve checked the permalinks codex page and the forums but couldn’t find what I was looking for.

    I’m migrating an existing website to wordpress and need to have all my ‘static’ pages end in .html. I’m using the Pages feature of wordpress to create these pages and using the basic permalink structure: /what-we-do/seo-for-etailers/
    I need to be able to have that URI end in a .html:
    what-we-do/seo-for-etailers.html Anyone know a mod_rewrite rule that could achieve this? It’s quite important as I dont wont to be serving broken links.

    Cheers
    Darren

Viewing 9 replies - 1 through 9 (of 9 total)
  • You should be able to do this under Options > Permalinks, so that if your current permalink structure looks something like this:

    /%year%/%monthnum%/%day%/%postname%/

    change it to this:

    /%year%/%monthnum%/%day%/%postname%.html

    Thread Starter darren131

    (@darren131)

    Sorry i should have stated that I have done that already. That rule on the permalinks option page only works for posts, not pages ??

    So what you really want are .htaccess rules that recognize the
    what-we-do/seo-for-etailers.html
    links and send them to the new WP
    /what-we-do/seo-for-etailers/
    URL, right? In other words, why muck about with hacking up permalinks when you can do that all in .htaccess.

    Thread Starter darren131

    (@darren131)

    yes – thats right…like I said in my first post:
    “Anyone know a mod_rewrite rule that could achieve this?”

    Hello,

    I need to replace the – (dash) with an _ (underscore) in my permalink structure. Ex: https://www.domain.com/blog/index.php/2005/09/07/why_do_anxieties_and_phobias_occur

    Somebody help me in this.

    Regards

    Akhil

    Stick to one thread, ak1jain. You already got an answer.

    Hi Darren131,

    This what I did so all uris will end .html

    Edit wp-incudes/classes.php

    Find the class ‘class WP’ and look for


    $req_uri = str_replace($pathinfo, '', $req_uri);
    $req_uri = str_replace($home_path, '', $req_uri);

    and add this after the above


    $req_uri = str_replace('.html', '', $req_uri);

    This will remove the .html out of uri

    Now we add it

    Edit wp-includes/template-functions-links.php

    Find this


    return apply_filters('post_link', get_settings('home') . str_replace($rewritecode, $rewritereplace, $permalink), $post);

    and edit to look like this


    return apply_filters('post_link', get_settings('home') . str_replace($rewritecode, $rewritereplace, $permalink), $post) .'.html';

    This adds .html to all posts.

    Now we can add the .html to all pages

    Find this, its down the page about 20 lines


    $link = get_page_uri($id);
    $link = str_replace('%pagename%', $link, $pagestruct);
    $link = get_settings('home') . "/$link/";

    Edit it to like:

    $link = get_page_uri($id);
    $link = str_replace('%pagename%', $link, $pagestruct);
    $link = get_settings('home') . "/$link.html";

    Just remove the / and replace with .html, now all pages will end in .html.

    Now find function trailingslashit in the page function_formating.php


    function trailingslashit($string) {
    if ( '/' != substr($string, -1)) {
    $string .= '/';
    }
    return $string;
    }

    Change the string to


    $string .= '.html';

    Now that will add the .html to the uri for calendar,months, etc

    Robert

    Hello.

    This works for all pages and posts. However, it does not work for archived posts that go beyond the first page.

    For example, the NEXT PAGE link at the bottom of the posts looks like:

    https://websiteurl.com.php.phppage/2.php

    Thus, all posts beyond the first page of posts cannot be found.

    Here is the code in question:

    ———-> (index.php)

    <?php posts_nav_link(‘ — ‘, __(‘« Previous Page’), __(‘Next Page »’)); ?>

    <———-

    Did anyone fix this so it does work throughout?

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Page permalinks with .html extension’ is closed to new replies.