• i need to rewrite the url path of my href internal links. I got into my site relative and absolute links.

    ex.

    <a href=”https://www.sitename.com/pippo&#8221;
    <a href=”/pippo”
    <a href=”/pippo/”

    I need a php function to insert inside child theme that check if an href is internal links and check the last char of url path and then if there isn’t as last char the ‘/’ apply it to internal links with href.

    Only inside the posts and pages.

    This to avoid the huge 301 redirection quantity.

    Thanks for your support.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Thread Starter gennymac

    (@gennymac)

    sorry but it’s impossible to use this plugin due to i got a lot of internal links. I need a function so in every case it follow the final slash.

    Moderator bcworkz

    (@bcworkz)

    You could use “the_content” filter to parse through all content upon output, looking for links without a trailing slash and adding one as needed. It’s pretty inefficient to do this for any post or page request, doing the same thing over and over again. Why not permanently correct the URLs as they sit in the DB?

    The better search replace plugin previously referenced may not have the power to properly do this, but the plugin is based on the tool from interconnect/it. This tool is much more powerful because it supports regexp search patterns. I recommend you use it to permanently correct all of your internal URLs. This does require some regexp knowledge. If you don’t know regexp, it’s not that hard to learn just enough to do the job.

    You can try out your regexp pattern by using the dry run option where no actual changes are made, but you can still see the results of your regexp replacement. There are also several websites that let your try out a regexp pattern on sample data. regexr.com is one example. It also has resources that help you learn regexp and better understand what the various regexp tokens do.

    Thread Starter gennymac

    (@gennymac)

    thanks for your reply, but it’s so difficult to use regex pattern for my case.

    I need to check where inside href there is sitename with www. not www, with https, without https, now i’m trying to remove the sitename from all links, so they will be only relative /pippo/…..

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Rewrite url path for internal links’ is closed to new replies.