Forums

Forcing Pages to use File Extensions (22 posts)

  1. skipcollege
    Member
    Posted 5 years ago #

    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!

  2. skipcollege
    Member
    Posted 5 years ago #

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

  3. Chris_K
    Member
    Posted 5 years ago #

  4. skipcollege
    Member
    Posted 5 years ago #

    Thanks for the try HandySolo but I'm referring to WordPress Pages not blog posts. ;)

  5. Nazgul
    Member
    Posted 5 years ago #

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

  6. skipcollege
    Member
    Posted 5 years ago #

    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? $$$

  7. Nazgul
    Member
    Posted 5 years ago #

    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);

  8. skipcollege
    Member
    Posted 5 years ago #

    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!

  9. Nazgul
    Member
    Posted 5 years ago #

    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.

  10. skipcollege
    Member
    Posted 5 years ago #

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

    Thanks a ton!! :)

  11. Nazgul
    Member
    Posted 5 years ago #

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

  12. skipcollege
    Member
    Posted 5 years ago #

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

  13. Haecceity
    Member
    Posted 5 years ago #

    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?

  14. Haecceity
    Member
    Posted 5 years ago #

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

  15. skipcollege
    Member
    Posted 5 years ago #

    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!

  16. skipcollege
    Member
    Posted 5 years ago #

    bump #1!

  17. skipcollege
    Member
    Posted 5 years ago #

    bump #2!

  18. skipcollege
    Member
    Posted 5 years ago #

    bump #3!

    Doesn't this just take a simple if-then statement in the right place to apply this only to wordpress pages?

  19. skipcollege
    Member
    Posted 5 years ago #

    bump #4!

    Doesn't this just take a simple if-then statement in the right place to apply this only to wordpress pages?

    Could someone possibly help me out?

    Thank you!! :)

  20. skipcollege
    Member
    Posted 5 years ago #

    I need to solve this asap because the site is going live very soon.

    I believe I described the situation very clearly a few posts back here... http://wordpress.org/support/topic/75826?replies=19#post-476547

    I've been working on this for hours and haven't been able to get the right php statement to check if it is a page.

    I've tried many variations of something like this...

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

    I'm assuming all it takes is a simple php if statement to apply this to only wordpress pages and not blog posts.

    If so then all I need is an if statement that works in includes/classes.php that checks if the current webpage being viewed is a wordpress page or post. Then I want to apply the functioning file extension hack that I have to only pages and not both pages and posts like it is now.

    If my assumptions are right this should be very easy for someone who knows php and is familiar with wordpress. I really need to solve this asap and could use some help.

    Thank you!

  21. skipcollege
    Member
    Posted 5 years ago #

    bump...I haven't heard from anyone for over a month! I believe this just comes down to 1 line of simple code. (If this is WP Page and not Post...do my hack) Could someone take a shot at it for me please!?

    Thank you!

  22. vincentrich
    Member
    Posted 5 years ago #

    Have you found a solution to this? I am interested to get this to work for my WordPress pages too but without hacking any files.

Topic Closed

This topic has been closed to new replies.

About this Topic