Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter johnwuser1245

    (@johnwuser1245)

    Solved:
    Created my own plugin that works well with simply_static. Now it works well. You run the plugin in the url after you have done the simply static generate. It makes sure everything is relative

    <?php
    /*
    Plugin Name: Static Post Export URL Fix
    Description: Rewrites staging URLs inside the exported static site.
    Version: 1.2
    Author: Admin
    */

    if ( ! defined('ABSPATH') ) exit; // Prevent direct access

    // Run only when visiting the admin-post URL
    add_action('admin_post_fix_static_urls', function() {

    // Export folder (replace with your actual path)
    $export_dir = '/path/to/static_export';

    if (!is_dir($export_dir)) {
    wp_die("Export directory not found.");
    }

    // Staging URLs to replace
    $domains = [
    'http://staging.example.internal',
    'https://staging.example.internal',
    'http://internal-ip',
    'https://internal-ip'
    ];

    $files = 0;
    $changed = 0;

    $iterator = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator($export_dir, RecursiveDirectoryIterator::SKIP_DOTS)
    );

    foreach ($iterator as $file) {
    if (!$file->isFile()) continue;

    $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
    if (!in_array($ext, ['html','htm','js','css','json','xml'])) continue;

    $path = $file->getPathname();
    $content = file_get_contents($path);
    $original = $content;

    foreach ($domains as $d) {
    // Replace normal and escaped URLs
    $content = str_replace([$d, str_replace('/', '\/', $d)], '', $content);
    }

    if ($content !== $original) {
    file_put_contents($path, $content);
    $changed++;
    }

    $files++;
    }

    // Write log
    $log = "/tmp/static-url-fix.log";
    file_put_contents(
    $log,
    date('c')." scanned:$files changed:$changed\n",
    FILE_APPEND
    );

    echo "Done. Scanned $files files. Changed $changed files.";
    exit;
    });
    • This reply was modified 2 months, 2 weeks ago by johnwuser1245.
    Thread Starter johnwuser1245

    (@johnwuser1245)

    Thank you for your answer. Unfortunately this does not work. Everything gets replaced with relative paths except for everything related in /wp-content jetmenu and etc. You can see an example here:
    news/index.html:{"baseUrl":"https://s.w.org/images/core/emoji/17.0.2/72x72/","ext":".png","svgUrl":"https://s.w.org/images/core/emoji/17.0.2/svg/","svgExt":".svg","source":{"concatemoji":"http://10.16.205.66/wp-includes/js/wp-emoji-release.min.js?ver=6.9.1"}}
    news/index.html://# sourceURL=http://10.16.205.66/wp-includes/js/wp-emoji-loader.min.js

    news/index.html:<script src="http://10.16.205.66/wp-content/plugins/elementor-pro/assets/js/frontend.min.js?ver=3.35.1" id="elementor-pro-frontend-js"></script>
    news/index.html:<script src="http://10.16.205.66/wp-content/plugins/elementor-pro/assets/js/elements-handlers.min.js?ver=3.35.1" id="pro-elements-handlers-js"></script>
    news/index.html:<script src="http://10.16.205.66/wp-content/plugins/jet-menu/includes/elementor/assets/public/js/legacy/widgets-scripts.js?ver=2.4.18" id="jet-menu-elementor-widgets-scripts-js"></script>
    news/index.html:{"baseUrl":"https://s.w.org/images/core/emoji/17.0.2/72x72/","ext":".png","svgUrl":"https://s.w.org/images/core/emoji/17.0.2/svg/","svgExt":".svg","source":{"concatemoji":"http://10.16.205.66/wp-includes/js/wp-emoji-release.min.js?ver=6.9.1"}}
    news/index.html://# sourceURL=http://10.16.205.66/wp-includes/js/wp-emoji-loader.min.js


    I tried absolute mode for debugging and it worked fine. Everything was replaced. The only problem was I could not access my staging sites urls because it was pointing to my public domain instead. Which is normal/expected

    I have also made sure to follow step 1,2,5,6. The other steps does not exist in my ui for simply-static 3.6.2. I export in local mode.

    I have contacted the elementor and followed their steps to make sure too. But they are pointing me to that there is an issue with simply-static not replacing or my nginx servers.

    The filter code you gave me, I am a bit unsure where to add that. I will figure out if you still think that’s the issue

    Thread Starter johnwuser1245

    (@johnwuser1245)

    Hi, could a moderator please remove my domain name from my post? I accidentally included it.

Viewing 3 replies - 1 through 3 (of 3 total)