Support » Plugins » Forcing Pages to use File Extensions

  • Hello, I have searched and found 6 or 7 posts on this topic but no one had a solution. However, I am in absolute need of this functionality for a website. On static WP Pages (not blog posts) we need the page urls to be domain.com/about.xyz and not the default domain.com/about/. Does anyone have the hack to accomplish this? I’m in need of this and am even willing to pay for it asap. Thanks!

Viewing 15 replies - 1 through 15 (of 21 total)
  • Thread Starter skipcollege

    (@skipcollege)

    bump! Can this be done? Anyone with php skills want to help me out?

    Thread Starter skipcollege

    (@skipcollege)

    Thanks for the try HandySolo but I’m referring to WordPress Pages not blog posts. 😉

    Pages apply to the same rules as Posts concerning permalinks, so HandySolo’s solution should be correct.

    Thread Starter skipcollege

    (@skipcollege)

    Just tested it again on my WP site and they work separately. When I create a Page titled ‘About’ the url turns out as domain.com/about/ so I go to edit the page and change the slug from ‘about’ to ‘about.html’ and the url turns out as domain.com/abouthtml/. Other posts I’ve read by people have confirmed this too.

    Anyone want to hack it for me? $$$

    Unsupported hack ([ is < and ] is >):

    In wp-includes/template-functions-post.php, at line 419:
    $output .= $indent . ‘[li class=”‘ . $css_class . ‘”][a href=”‘ . rtrim(get_page_link($page_id)>, ‘/’) . ‘.html” title=”‘ . wp_specialchars($title) . ‘”]’ . $title . ‘[/a]’;

    In wp-includes/classes.php, at line 1510:
    $req_uri = preg_replace(“|^$home_path|”, ”, $req_uri);
    $req_uri = preg_replace(“|.html$|”, ”, $req_uri);

    Thread Starter skipcollege

    (@skipcollege)

    I tried the code out and it is changing the url but not working correctly… It is changing every new page into “domain.com/1.html”. Everyone ends in “1.html”.

    In wp-includes/template-functions-post.php, at line 419 I replaced

    $output .= $indent . ‘[li class=”‘ . $css_class . ‘”][a href=”‘ . get_page_link($page_id) . ‘” title=”‘ . wp_specialchars($title) . ‘”]’ . $title . ‘[/a]’;

    with your code…

    $output .= $indent . ‘[li class=”‘ . $css_class . ‘”][a href=”‘ . rtrim(get_page_link($page_id)>, ‘/’) . ‘.html” title=”‘ . wp_specialchars($title) . ‘”]’ . $title . ‘[/a]’;

    I initially received an error about an unexpected comma “,” on this 419 line so I deleted the comma after “($page_id)>” and the error went away.

    In wp-includes/classes.php, at line 1510 I replaced

    $req_uri = preg_replace(“|^$home_path|”, ”, $req_uri);
    $req_uri = trim($req_uri, ‘/’);

    with your code…

    $req_uri = preg_replace(“|^$home_path|”, ”, $req_uri);
    $req_uri = preg_replace(“|.html$|”, ”, $req_uri);

    Did I implement it correctly by replacing those lines in these two files?

    If this can be altered to work that would be great!

    I made a typo in the first line above. (Note the removed >)

    In wp-includes/template-functions-post.php, at line 419:
    $output .= $indent . ‘[li class=”‘ . $css_class . ‘”][a href=”‘ . rtrim(get_page_link($page_id), ‘/’) . ‘.html” title=”‘ . wp_specialchars($title) . ‘”]’ . $title . ‘[/a]’;

    And for the second edit. Only replace the 1 line with the 2 I posted. So don’t replace the trim one.

    Thread Starter skipcollege

    (@skipcollege)

    Wow, awesome! It works like a charm! Can I PayPal you $10 for your help Nazgul?

    Thanks a ton!! 🙂

    Thanks for the offer, but keep the money. I was just curious if I could get this to work. 🙂

    Thread Starter skipcollege

    (@skipcollege)

    Well thank you for the code Nazgul, it helped me out immensely!

    Bodhipaksa

    (@haecceity)

    I’m hoping Nazgul’s still around or that someone else can help me with this.

    I tried using the code changes above to add a html extension on my Pages. It worked fine until I implemented the foldpage plugin, whereupon I was back to having a trailing slash after the filename. Anyone have any ideas how to have both foldpage and an html extension on Pages?

    Bodhipaksa

    (@haecceity)

    Well, I deactivated the foldpage plugin, and so that kinda sorted the problem.

    Thread Starter skipcollege

    (@skipcollege)

    I’m having a little conflict with this hack now and am so close to having it work right again in 2.0.5.

    I have $req_uri = preg_replace(“|.html$|”, ”, $req_uri); inserted after $req_uri = preg_replace(“|^$home_path|”, ”, $req_uri); on line 1522 of wp-includes/classes.php.

    My wordpress pages are accessible at domain.com/pagename.html and domain.com/pagename which is fine.

    The problem comes in when I try to access my blog posts at their individual permalink urls. All of the links throughout the site and feeds point to the correct location which is domain.com/2006/11/postname.html. However when I browse to an individual blog post url I get a 404 error. But when I add another .html to that url it works. So the page displays itself properly at domain.com/2006/11/postname.html.html.

    So the hack is correctly making pages accessible with the .html extension added on but it is adding an extra .html onto the url of blog posts.

    It seems like this could be solved by adding some simple php logic to make the .html extension be applied to only wordpress pages.

    I attempted to do this by changing the original hack code, that I mentioned above, into this…

    if ( $this->is_page = true ) { $req_uri = preg_replace(“|.html$|”, ”, $req_uri); }

    It did not work. Would someone know how to make this adding of the file extension only apply to pages and not posts?

    Thank you!

    Thread Starter skipcollege

    (@skipcollege)

    bump #1!

Viewing 15 replies - 1 through 15 (of 21 total)
  • The topic ‘Forcing Pages to use File Extensions’ is closed to new replies.