最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

admin - Theme javascriptcss 404

programmeradmin4浏览0评论

I have recently installed WordPress 5.9.2 on my VPS using Apache2 on Debian 11. I want to try some different themes (partially because I think the editor for the new Twenty Twenty-Two theme is clunky and lacks stuff). However I noticed that after changing themes, no styles were loaded leaving an ugly page.

Looking into the developed console in Firefox, I saw that I was getting 404 errors when loading any resources. I also noticed that I got the same issue when using the default Twenty Twenty-Two theme, except that it at least looked correct. According to the Firefox developer console, I am getting 404's when trying to load various assets. Opening the url's manually confirmed that there is indeed a 404, and that pretty permalinks is working as I am getting a 404 page from WordPress, rather then from Apache.

I confirmed that the files do indeed exist on disk, and that they have the correct permissions. What is causing this error?

ile premissions for themes Twenty Twenty-Two themes dir

minecraftchest1@Docker:~$ ls /var/www/wordpress/wp-content/themes/twentytwentytwo/ -al
total 216
drwxrwxrwx 6 www-data sudo   4096 Mar 11 00:39 .
drwxrwxrwx 7 www-data sudo   4096 Mar 17 14:17 ..
drwxrwxrwx 5 www-data sudo   4096 Mar 11 00:39 assets
-rw-rw-rw- 1 www-data sudo   3632 Dec 20 16:50 functions.php
drwxrwxrwx 3 www-data sudo   4096 Mar 11 00:39 inc
-rw-rw-rw- 1 www-data sudo    216 Nov  9 21:02 index.php
drwxrwxrwx 2 www-data sudo   4096 Mar 11 00:39 parts
-rw-rw-rw- 1 www-data sudo   3538 Feb 21 21:15 readme.txt
-rw-rw-rw- 1 www-data sudo 162290 Nov  9 21:02 screenshot.png
-rw-rw-rw- 1 www-data sudo   5602 Feb 21 21:15 style.css
drwxrwxrwx 2 www-data sudo   4096 Mar 11 00:39 templates
-rw-rw-rw- 1 www-data sudo   9157 Jan  3 20:26 theme.json
minecraftchest1@Docker:~$ 

File Permissions for Twenty-Nineteen themes dir

minecraftchest1@Docker:~$ ls /var/www/wordpress/wp-content/themes/twentynineteen -al
total 992
drwxrwxrwx  9 www-data www-data   4096 Mar 17 14:17 .
drwxrwxrwx  7 www-data sudo       4096 Mar 17 14:17 ..
-rw-rw-rw-  1 www-data www-data    879 Mar 17 14:17 404.php
-rw-rw-rw-  1 www-data www-data   1297 Mar 17 14:17 archive.php
drwxrwxrwx  2 www-data www-data   4096 Mar 17 14:17 classes
-rw-rw-rw-  1 www-data www-data   4132 Mar 17 14:17 comments.php
drwxrwxrwx  2 www-data www-data   4096 Mar 17 14:17 fonts
-rw-rw-rw-  1 www-data www-data   1679 Mar 17 14:17 footer.php
-rw-rw-rw-  1 www-data www-data  11624 Mar 17 14:17 functions.php
-rw-rw-rw-  1 www-data www-data   1937 Mar 17 14:17 header.php
-rw-rw-rw-  1 www-data www-data   2984 Mar 17 14:17 image.php
drwxrwxrwx  2 www-data www-data   4096 Mar 17 14:17 images
drwxrwxrwx  2 www-data www-data   4096 Mar 17 14:17 inc
-rw-rw-rw-  1 www-data www-data   1113 Mar 17 14:17 index.php
drwxrwxrwx  2 www-data www-data   4096 Mar 17 14:17 js
-rw-rw-rw-  1 www-data www-data 116463 Mar 17 14:17 package-lock.json
-rw-rw-rw-  1 www-data www-data   1527 Mar 17 14:17 package.json
-rw-rw-rw-  1 www-data www-data    804 Mar 17 14:17 page.php
-rw-rw-rw-  1 www-data www-data    232 Mar 17 14:17 postcss.config.js
-rw-rw-rw-  1 www-data www-data   4111 Mar 17 14:17 print.css
-rw-rw-rw-  1 www-data www-data   3517 Mar 17 14:17 print.scss
-rw-rw-rw-  1 www-data www-data   4317 Mar 17 14:17 readme.txt
drwxrwxrwx 13 www-data www-data   4096 Mar 17 14:17 sass
-rw-rw-rw-  1 www-data www-data 175535 Mar 17 14:17 screenshot.png
-rw-rw-rw-  1 www-data www-data   1417 Mar 17 14:17 search.php
-rw-rw-rw-  1 www-data www-data   1847 Mar 17 14:17 single.php
-rw-rw-rw-  1 www-data www-data    164 Mar 17 14:17 style-editor-customizer.css
-rw-rw-rw-  1 www-data www-data    162 Mar 17 14:17 style-editor-customizer.scss
-rw-rw-rw-  1 www-data www-data  80824 Mar 17 14:17 style-editor.css
-rw-rw-rw-  1 www-data www-data  19569 Mar 17 14:17 style-editor.scss
-rw-rw-rw-  1 www-data www-data 232516 Mar 17 14:17 style-rtl.css
-rw-rw-rw-  1 www-data www-data 232720 Mar 17 14:17 style.css
-rw-rw-rw-  1 www-data www-data  15717 Mar 17 14:17 style.css.map
-rw-rw-rw-  1 www-data www-data   3397 Mar 17 14:17 style.scss
drwxrwxrwx  6 www-data www-data   4096 Mar 17 14:17 template-parts
minecraftchest1@Docker:~$ 

Content of wp-config.php

minecraftchest1@Docker:~$ cat /var/www/wordpress/wp-config.php 
<?php

/**
 * The base configuration for WordPress
 *
 * The wp-config.php creation script uses this file during the installation.
 * You don't have to use the web site, you can copy this file to "wp-config.php"
 * and fill in the values.
 *
 * This file contains the following configurations:
 *
 * * Database settings
 * * Secret keys
 * * Database table prefix
 * * ABSPATH
 *
 * @link /
 *
 * @package WordPress
 */

// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );

/** Database username */
define( 'DB_USER', 'wordpress' );

/** Database password */
define( 'DB_PASSWORD', '<!--Removed-->' );

/** Database hostname */
define( 'DB_HOST', 'localhost' );

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8mb4' );

/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

// Locked out of site.
define('WP_HOME',    '' );

define('WP_SITEURL', '' );

define( 'WP_CONTENT_URL', '');

if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';


/**#@+
 * Authentication unique keys and salts.
 *
 * Change these to different unique phrases! You can generate these using
 * the {@link .1/salt/ WordPress secret-key service}.
 *
 * You can change these at any point in time to invalidate all existing cookies.
 * This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define( 'AUTH_KEY',         'HUYM] y6cfgYnA_,di@24ga#oxoVc.OwG_c FUpL`Yd8LDG./TKfA-6*0p<y3+rt' );
define( 'SECURE_AUTH_KEY',  '3}|-PqLE26pl^[S$MW52C{mH:Lr=}+HiJju4R`xxP[*3=KM#Xkzn9]ruqOUQNf7T' );
define( 'LOGGED_IN_KEY',    'g])CKZvHZ_:}#M61(iZqn.vndN-c`=;!o02_[K]%d~?6)K..I5e_-b3o_dLgk4kW' );
define( 'NONCE_KEY',        '+mW[)=;=krG`M]kXR7)n){|F^RDo.JY^NxMZ<sk>BI%I2Ijp>sa/9<Nig^`-z&J,' );
define( 'AUTH_SALT',        'KHDiavb$?H/:A>b6}I6/YrLM*PiK8j,kg4rAMW$pGz|B:c8:)o5bu)hBPyvla{xy' );
define( 'SECURE_AUTH_SALT', 'nP@zIfto.@9-jPTuG:NmZs;f<p-%Y7RIYAOjzuK&xH7?`azD|r2ZQ2t8}J>f^[oG' );
define( 'LOGGED_IN_SALT',   'u[`I&!CmM{ }?ZE%{!aFK1M-5L=X/@~zMwAG!n^UR7*)#ZoDM,TCjA}m2(kRbtq6' );
define( 'NONCE_SALT',       ',x1W)t x0h)HpQDYW^NaE.%3MVT>zy%Gw0%J0&jS<1G JNJ~Ikc#dO=Aqn6>EV_=' );

/**#@-*/

/**
 * WordPress database table prefix.
 *
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
 */
$table_prefix = 'wp1_';

/**
 * For developers: WordPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 *
 * For information on other constants that can be used for debugging,
 * visit the documentation.
 *
 * @link /
 */
define( 'WP_DEBUG', false );

/* Add any custom values between this line and the "stop editing" line. */



/* That's all, stop editing! Happy publishing. */

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
        define( 'ABSPATH', __DIR__ . '/' );
}

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';
minecraftchest1@Docker:~$ 

I have recently installed WordPress 5.9.2 on my VPS using Apache2 on Debian 11. I want to try some different themes (partially because I think the editor for the new Twenty Twenty-Two theme is clunky and lacks stuff). However I noticed that after changing themes, no styles were loaded leaving an ugly page.

Looking into the developed console in Firefox, I saw that I was getting 404 errors when loading any resources. I also noticed that I got the same issue when using the default Twenty Twenty-Two theme, except that it at least looked correct. According to the Firefox developer console, I am getting 404's when trying to load various assets. Opening the url's manually confirmed that there is indeed a 404, and that pretty permalinks is working as I am getting a 404 page from WordPress, rather then from Apache.

I confirmed that the files do indeed exist on disk, and that they have the correct permissions. What is causing this error?

ile premissions for themes Twenty Twenty-Two themes dir

minecraftchest1@Docker:~$ ls /var/www/wordpress/wp-content/themes/twentytwentytwo/ -al
total 216
drwxrwxrwx 6 www-data sudo   4096 Mar 11 00:39 .
drwxrwxrwx 7 www-data sudo   4096 Mar 17 14:17 ..
drwxrwxrwx 5 www-data sudo   4096 Mar 11 00:39 assets
-rw-rw-rw- 1 www-data sudo   3632 Dec 20 16:50 functions.php
drwxrwxrwx 3 www-data sudo   4096 Mar 11 00:39 inc
-rw-rw-rw- 1 www-data sudo    216 Nov  9 21:02 index.php
drwxrwxrwx 2 www-data sudo   4096 Mar 11 00:39 parts
-rw-rw-rw- 1 www-data sudo   3538 Feb 21 21:15 readme.txt
-rw-rw-rw- 1 www-data sudo 162290 Nov  9 21:02 screenshot.png
-rw-rw-rw- 1 www-data sudo   5602 Feb 21 21:15 style.css
drwxrwxrwx 2 www-data sudo   4096 Mar 11 00:39 templates
-rw-rw-rw- 1 www-data sudo   9157 Jan  3 20:26 theme.json
minecraftchest1@Docker:~$ 

File Permissions for Twenty-Nineteen themes dir

minecraftchest1@Docker:~$ ls /var/www/wordpress/wp-content/themes/twentynineteen -al
total 992
drwxrwxrwx  9 www-data www-data   4096 Mar 17 14:17 .
drwxrwxrwx  7 www-data sudo       4096 Mar 17 14:17 ..
-rw-rw-rw-  1 www-data www-data    879 Mar 17 14:17 404.php
-rw-rw-rw-  1 www-data www-data   1297 Mar 17 14:17 archive.php
drwxrwxrwx  2 www-data www-data   4096 Mar 17 14:17 classes
-rw-rw-rw-  1 www-data www-data   4132 Mar 17 14:17 comments.php
drwxrwxrwx  2 www-data www-data   4096 Mar 17 14:17 fonts
-rw-rw-rw-  1 www-data www-data   1679 Mar 17 14:17 footer.php
-rw-rw-rw-  1 www-data www-data  11624 Mar 17 14:17 functions.php
-rw-rw-rw-  1 www-data www-data   1937 Mar 17 14:17 header.php
-rw-rw-rw-  1 www-data www-data   2984 Mar 17 14:17 image.php
drwxrwxrwx  2 www-data www-data   4096 Mar 17 14:17 images
drwxrwxrwx  2 www-data www-data   4096 Mar 17 14:17 inc
-rw-rw-rw-  1 www-data www-data   1113 Mar 17 14:17 index.php
drwxrwxrwx  2 www-data www-data   4096 Mar 17 14:17 js
-rw-rw-rw-  1 www-data www-data 116463 Mar 17 14:17 package-lock.json
-rw-rw-rw-  1 www-data www-data   1527 Mar 17 14:17 package.json
-rw-rw-rw-  1 www-data www-data    804 Mar 17 14:17 page.php
-rw-rw-rw-  1 www-data www-data    232 Mar 17 14:17 postcss.config.js
-rw-rw-rw-  1 www-data www-data   4111 Mar 17 14:17 print.css
-rw-rw-rw-  1 www-data www-data   3517 Mar 17 14:17 print.scss
-rw-rw-rw-  1 www-data www-data   4317 Mar 17 14:17 readme.txt
drwxrwxrwx 13 www-data www-data   4096 Mar 17 14:17 sass
-rw-rw-rw-  1 www-data www-data 175535 Mar 17 14:17 screenshot.png
-rw-rw-rw-  1 www-data www-data   1417 Mar 17 14:17 search.php
-rw-rw-rw-  1 www-data www-data   1847 Mar 17 14:17 single.php
-rw-rw-rw-  1 www-data www-data    164 Mar 17 14:17 style-editor-customizer.css
-rw-rw-rw-  1 www-data www-data    162 Mar 17 14:17 style-editor-customizer.scss
-rw-rw-rw-  1 www-data www-data  80824 Mar 17 14:17 style-editor.css
-rw-rw-rw-  1 www-data www-data  19569 Mar 17 14:17 style-editor.scss
-rw-rw-rw-  1 www-data www-data 232516 Mar 17 14:17 style-rtl.css
-rw-rw-rw-  1 www-data www-data 232720 Mar 17 14:17 style.css
-rw-rw-rw-  1 www-data www-data  15717 Mar 17 14:17 style.css.map
-rw-rw-rw-  1 www-data www-data   3397 Mar 17 14:17 style.scss
drwxrwxrwx  6 www-data www-data   4096 Mar 17 14:17 template-parts
minecraftchest1@Docker:~$ 

Content of wp-config.php

minecraftchest1@Docker:~$ cat /var/www/wordpress/wp-config.php 
<?php

/**
 * The base configuration for WordPress
 *
 * The wp-config.php creation script uses this file during the installation.
 * You don't have to use the web site, you can copy this file to "wp-config.php"
 * and fill in the values.
 *
 * This file contains the following configurations:
 *
 * * Database settings
 * * Secret keys
 * * Database table prefix
 * * ABSPATH
 *
 * @link https://wordpress.org/support/article/editing-wp-config-php/
 *
 * @package WordPress
 */

// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );

/** Database username */
define( 'DB_USER', 'wordpress' );

/** Database password */
define( 'DB_PASSWORD', '<!--Removed-->' );

/** Database hostname */
define( 'DB_HOST', 'localhost' );

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8mb4' );

/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

// Locked out of site.
define('WP_HOME',    'https://wp.arsrobotics.org' );

define('WP_SITEURL', 'http://wp.arsrobotics.org' );

define( 'WP_CONTENT_URL', 'https://wp.arsrobotics.org');

if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';


/**#@+
 * Authentication unique keys and salts.
 *
 * Change these to different unique phrases! You can generate these using
 * the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}.
 *
 * You can change these at any point in time to invalidate all existing cookies.
 * This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define( 'AUTH_KEY',         'HUYM] y6cfgYnA_,di@24ga#oxoVc.OwG_c FUpL`Yd8LDG./TKfA-6*0p<y3+rt' );
define( 'SECURE_AUTH_KEY',  '3}|-PqLE26pl^[S$MW52C{mH:Lr=}+HiJju4R`xxP[*3=KM#Xkzn9]ruqOUQNf7T' );
define( 'LOGGED_IN_KEY',    'g])CKZvHZ_:}#M61(iZqn.vndN-c`=;!o02_[K]%d~?6)K..I5e_-b3o_dLgk4kW' );
define( 'NONCE_KEY',        '+mW[)=;=krG`M]kXR7)n){|F^RDo.JY^NxMZ<sk>BI%I2Ijp>sa/9<Nig^`-z&J,' );
define( 'AUTH_SALT',        'KHDiavb$?H/:A>b6}I6/YrLM*PiK8j,kg4rAMW$pGz|B:c8:)o5bu)hBPyvla{xy' );
define( 'SECURE_AUTH_SALT', 'nP@zIfto.@9-jPTuG:NmZs;f<p-%Y7RIYAOjzuK&xH7?`azD|r2ZQ2t8}J>f^[oG' );
define( 'LOGGED_IN_SALT',   'u[`I&!CmM{ }?ZE%{!aFK1M-5L=X/@~zMwAG!n^UR7*)#ZoDM,TCjA}m2(kRbtq6' );
define( 'NONCE_SALT',       ',x1W)t x0h)HpQDYW^NaE.%3MVT>zy%Gw0%J0&jS<1G JNJ~Ikc#dO=Aqn6>EV_=' );

/**#@-*/

/**
 * WordPress database table prefix.
 *
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
 */
$table_prefix = 'wp1_';

/**
 * For developers: WordPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 *
 * For information on other constants that can be used for debugging,
 * visit the documentation.
 *
 * @link https://wordpress.org/support/article/debugging-in-wordpress/
 */
define( 'WP_DEBUG', false );

/* Add any custom values between this line and the "stop editing" line. */



/* That's all, stop editing! Happy publishing. */

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
        define( 'ABSPATH', __DIR__ . '/' );
}

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';
minecraftchest1@Docker:~$ 

Share Improve this question edited Mar 17, 2022 at 16:28 Minecraftchest1 asked Mar 17, 2022 at 15:12 Minecraftchest1Minecraftchest1 114 bronze badges 5
  • 1 Well the URLs in the console errors are clearly missing the wp-content/ directory. Have you done anything to try and change/obfuscate the wp-content directory? Is there anything related to it in your wp-config.php file? – Jacob Peattie Commented Mar 17, 2022 at 15:55
  • I have not done anything to the wp-content directory. I don't know what would you mean by anything related in the wp-config.php file. The only thing I have added there is a static decleration of the site url. – Minecraftchest1 Commented Mar 17, 2022 at 16:04
  • Please add this "static declaration" change to the wp-config file to your question. – jdm2112 Commented Mar 17, 2022 at 16:21
  • I updated the question. – Minecraftchest1 Commented Mar 17, 2022 at 16:28
  • define( 'WP_CONTENT_URL', 'https://wp.arsrobotics.org'); is exactly what I was talking about, and is what’s causing your problem. You should remove this or correct it to point to the URL for the wp-content directory. – Jacob Peattie Commented Mar 17, 2022 at 17:32
Add a comment  | 

1 Answer 1

Reset to default 1

Thanks to @jacob peattie for helping me to figure this out. The issue is that I had WP_CONTENT_URL set incorrectly. Removing it fixed the issue. I could have added /wp-content to the url and it would've solved the issue as well.

To explain why this caused in issue, I turned to the docs. This page explains that the WP_CONTENT_URL variable (which I understand is set to $WP_SITE_URL . '/wp-content') which the content_url function returns (after removing any extra trailing slashes). This function is used by both WordPress core as well as any extra plugins to the relative url to where 3rd party content (which includes themes and plugins, as well as uploaded media) is stored.

Because the stylesheets, javascript, fonts, etc were stored with the theme, the browser was unable to find them as it was told to look in the wrong spot. The correct use to change WP_CONTENT_URL would be is you serve the wp-content url from another domain( possibly through a CDN) that is seperate from the rest of your wordpress site.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论