wp2static icon indicating copy to clipboard operation
wp2static copied to clipboard

404 on theme's assets, wrong path/URL

Open alexandre-tobia opened this issue 3 years ago • 3 comments

HI @leonstafford,

When generating static website, all of my static assets are not generated because of 404.

I've added logging line on your Crawler.php (L205) for showing the real URL used by the "getUrl" function:

if ( $response['code'] === 404 ) {
      $site_path = rtrim( SiteInfo::getURL( 'site' ), '/' );
      $url_slug = str_replace( $site_path, '', $url );
      WsLog::l( '404 for URL ' . $url_slug );

      WsLog::l( 'REAL URL ' . $url ); <===== HERE

      CrawlCache::rmUrl( $url_slug );
      $response['body'] = null;
  } elseif ( in_array( $response['code'], WP2STATIC_REDIRECT_CODES ) ) {
      $response['body'] = null;
  }

My wordpress site info:

site_path /Users/alexandretobia/Sites/nps/web/wp/
site_url http://nps.test/wp/
home_url http://nps.test/
includes_path /Users/alexandretobia/Sites/nps/web/wp/wp-includes/
includes_url http://nps.test/wp/wp-includes/
content_path /Users/alexandretobia/Sites/nps/web/app/
content_url http://nps.test/app/
uploads_path /Users/alexandretobia/Sites/nps/web/app/uploads/
uploads_url http://nps.test/app/uploads/
plugins_path /Users/alexandretobia/Sites/nps/web/app/plugins/
plugins_url http://nps.test/app/plugins/
themes_root_path /Users/alexandretobia/Sites/nps/web/app/themes/
themes_root_url http://nps.test/app/themes/
parent_theme_path /Users/alexandretobia/Sites/nps/web/app/themes/nps-wp/resources/
parent_theme_url http://nps.test/app/themes/nps-wp/resources/
child_theme_path /Users/alexandretobia/Sites/nps/web/app/themes/nps-wp/resources/
child_theme_url http://nps.test/app/themes/nps-wp/resources/

LOGS : 2021-06-08 13:01:58: REAL URL http://nps.test/Users/alexandretobia/Sites/nps/web/app/themes/nps-wp/resources/assets/styles/main.css 2021-06-08 13:01:58: 404 for URL /Users/alexandretobia/Sites/nps/web/app/themes/nps-wp/resources/assets/styles/main.css 2021-06-08 13:01:58: REAL URL http://nps.test/Users/alexandretobia/Sites/nps/web/app/themes/nps-wp/resources/assets/scripts/main.js 2021-06-08 13:01:58: 404 for URL /Users/alexandretobia/Sites/nps/web/app/themes/nps-wp/resources/assets/scripts/main.js 2021-06-08 13:01:58: REAL URL http://nps.test/Users/alexandretobia/Sites/nps/web/app/themes/nps-wp/resources/assets/mix-manifest.json 2021-06-08 13:01:58: 404 for URL /Users/alexandretobia/Sites/nps/web/app/themes/nps-wp/resources/assets/mix-manifest.json

I don't know why is he calling url like "http://nps.test/Users/alexandretobia/Sites/nps/web/app/themes/nps-wp/resources/assets/scripts/main.js"

Capture d’écran 2021-06-08 à 13 03 36

And a folder with "/Users/"...is created with corrupted files.

PHP version: 7.4.18 I'm using bedrock (roots.io)

Can you help me with that ?

Thanks a lot

alexandre-tobia avatar Jun 08 '21 11:06 alexandre-tobia

Thanks @alexandre-tobia! I don't have time right now to switch focus to it. Is there anyway with Bedrock to get the URL to not use a subdirectory for hosting? ie, drop the /wp and just serve WP from http://nps.test/? I think that wil be the main problem one. The /app/themes etc should be OK or a quicker fix.

leonstafford avatar Jun 25 '21 11:06 leonstafford

This gives some ideas: https://github.com/roots/bedrock/issues/180

As WP2Static is designed to run off dev environments, I wouldn't care about the security implications of adjusting things against their project's best practices - as long as your dev server isn't open to the public.

leonstafford avatar Jun 25 '21 11:06 leonstafford

#840 may help with this, once it's complete.

john-shaffer avatar Dec 02 '21 02:12 john-shaffer