• Hello,

    I’ve been struggling mightily with this question, and I can’t seem to handle it directly within .htaccess or within my theme functions.

    I’m trying to figure out how to remove any folder from the URL generated by WordPress, and then add “.html” to the end. So:

    Starting URL: https://www.domain.com/ANYFOLDER/any-page-name

    Ending URL: https://www.domain.com/any-page-name.html

    This Plug-In handles the “.html” part, but I’m still stuck on the folder portion, and both my attempts to handle this directly through .htaccess or through an add_rewrite_rule() function produce no results.

    Any assistance would be most appreciated!

Viewing 9 replies - 1 through 9 (of 9 total)
  • What do your Permalink settings look like?

    Thread Starter studio1337

    (@studio1337)

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

    But this is strictly for pages, not posts. To be honest, we rarely have clients who use WordPress for blogging, and unless I’m mistaken, the permalink structure cannot be extended to exert control over pages (unless there’s some sort of plug-in that does this?).

    You’re correct, page URLs start from the WordPress Address. Is your WordPress install located in a subfolder of the domain?

    Thread Starter studio1337

    (@studio1337)

    No, the install is in the root.

    When we create pages, we are creating then as parent/child pages.

    WHAT WE HAVE NOW:
    Home
    Section 1 = /Section-1
    — Page 1.1 = /Section-1/Page-1-1
    — Page 1.2 = /Section-1/Page-1-2
    Section 2 = /Section-2
    — Page 2.1 = /Section-2/Page-2-1
    — Page 2.2 = /Section-2/Page-2-2

    WHERE WE NEED TO END UP
    Home
    Section 1 = /Section-1.html
    — Page 1.1 = /Page-1-1.html
    — Page 1.2 = /Page-1-2.html
    Section 2 = /Section-2.html
    — Page 2.1 = /Page-2-1.html
    — Page 2.2 = /Page-2-2.html

    Removing the parent/child relationship between pages and using theme menus is not an option. There is too much automation in play here (sectional menus showing up based on parent/child, site map page, etc.). All we need is to write out the top-level folder. Just yank it out!

    And then add .html at the end. I know – it sounds silly, but it’s important in this specific project.

    Thread Starter studio1337

    (@studio1337)

    WordPress does a great job of being an open platform that is easy to program around. So why is this so hard? ??

    I’ve exhausted my searched through plug-ins, and I’ve tried countless rules through htaccess (which either fail to run or break the page) and add_rewrite_rule(), which have no effect on the page.

    If this is a difficult or complex bit of programming work to accomplish, I’d love to learn and would appreciate it someone could give me a head start on it. If this is simple, I’d love it if someone could help me construct this, and then I can deconstruct how it operates working off an existing sample.

    But I can’t be asking the impossible…am I?

    Does the end result URL absolutely have to look like you’re describing, or do you simply need links to follow your prescribed format? The reason I ask is that when WordPress receives a request for a page, it looks at the slug of each page to match to the URL, so that you can actually just include the slug after the domain and you’ll be served the proper page regardless of parent/child relationship.

    For example, on my site my Content License page is a child of my About page, so the URL is https://christiaanconover.com/about/license. However, entering https://christiaanconover.com/license still gets you to the page.

    If you simply need clean URLs to share, WordPress already supports that usage model. If you have to have the URL show the page slug relative to the root domain regardless of hierarchy, then you’re going to need to do some custom coding (assuming there isn’t a plugin out there that will do that), because you’re talking about modifying a core function of WordPress. WordPress is highly customizable, but that means code is required.

    I’d recommend you spend some time reading up on the Rewrite API if you’re able to write a plugin to achieve your desired result, as that will tell you whether what you’re looking to accomplish is possible.

    Thread Starter studio1337

    (@studio1337)

    Hi Christian,

    Thank you for the response. Unfortunately, the ending URL MUST be in the format described above. I’ll look into the API in more detail. I’m a decent programmer, but I will probably need to assign this to one of my guys who can soak it in more easily than I can.

    Thanks!

    No problem. I’m sure you’ve already done this but check to see whether any existing plugins address this. Good luck, and let us know if you get it sorted out.

    Additionally, if you need assistance with the coding, you may want to try the Hacks forum.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘remove folder from URL and add .html’ is closed to new replies.