在这里,我们将尝试删除 wordpress 中的 403 禁止。
错误原因
-
当我们将网站从一台服务器移动到另一台服务器时,就会出现这种类型的错误。然后可能存在未定义的 wordpress 网站根路径和 wordpress 核心目录 wp-admin、wp-includes 不可用的时间。
-
wordpress 中禁止出现错误 403 的第二个原因是由于网站根目录中缺少 .htaccess 文件。
-
wordpress 中禁止出现错误 403 的第三个原因是目录权限错误。您的 wordpress 目录权限应为 0755,文件权限应为 0644。
-
wordpress 中禁止出现错误 403 的另一个原因是 wordpress 网站的 URL 错误。
如何解决wordpress中禁止的错误403
**方法1:**设置WordPress目录的绝对路径
在您的 wordpress 根目录下打开 wp-config.php 并粘贴下面给出的代码。
/** Absolute path to the WordPress directory. */if ( !defined('ABSPATH') )define('ABSPATH', dirname(__FILE__) . '/');define('CONCATENATE_SCRIPTS', false);
进入全屏模式 退出全屏模式
添加此代码后,打开您的网站和 wordpress 仪表板。并且 403 错误禁止将消失。
**方法2:**在WordPress中创建.htaccess文件
在您的 wordpress 根目录下创建一个 .htaccess 文件并粘贴下面给出的代码。
# BEGIN WordPress<IfModule mod_rewrite.c>RewriteOptions inheritRewriteEngine onHeader set content-Security-Policy: upgrade-insecure-requestsRewriteBase /RewriteCond %{HTTPS} off# First rewrite to HTTPS:# Don't put www. here. If it is already there it will be included, if not# the subsequent rule will catch it.RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]# Now, rewrite any request to the wrong domain to use www.RewriteCond %{HTTP_HOST} !^www\.RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]RewriteRule ^index\.php
nbsp;- [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]</IfModule># END WordPress
进入全屏模式 退出全屏模式
在 wordpress 中创建 .htaccess 文件后,wordpress 中禁止的错误 403 将消失。
方法 3: 更改 WordPress 数据库中的路径和 URL
-
从 phpmyadmin 下载您的 wordpress 数据库。
-
保留您的 wordpress 数据库的备份。
-
然后在文本编辑器(Notepad、Notepad++、Sublime 等)中打开您的数据库文件。
-
找到单词 public_html 并将这个单词替换为您的 wordpress 网站的确切路径。例如,您会找到路径 home3/website_name/public_html,而您的网站新路径是 home/website_name/public_html。然后将 home3/website_name/public_html 替换为 home/website_name/public_html。
-
在数据库文件中找到您网站的旧网址,并在数据库文件中替换为您的 wordpress 网站的新网址。例如,您的旧网站 url 是 oldwebsite.com,而您的新网站 url 是 newwebsite.com。然后用 newwebsite.com 找到 oldwebsite.com
更改数据库文件后,保存数据库文件。删除 phpmyadmin 中的所有数据库表,并在 phpmyadmin 中上传这个更新的数据库文件。最后,wordpress 中禁止的错误 403 将消失。
**方法4:**更新WordPress核心文件
-
从 WordPress 网站下载您最新的 wordpress。
-
保留您的 wordpress 网站文件的备份。
-
打开文件管理器。在您的网站根目录下删除除 wp-content 目录之外的所有文件和目录。您不需要删除 wp-content 目录,因为它包含您的网站主题和插件。
-
现在上传新下载的 wordpress,除了 wp-content 目录。您不需要上传 wp-content 目录。
-
然后在你的网站根目录下打开 wp-config.php 文件。并输入您的数据库凭据、您的表前缀并输入身份验证唯一密钥和盐。您还可以阅读这篇文章 WordPress curl 错误 60 SSL 证书问题。请参阅下面的示例代码,或者您可以使用 wp-config.php 文件的此代码。
define('DB_NAME', 'databasename');/** MySQL database username */define('DB_USER', 'databaseusername');/** MySQL database password */define('DB_PASSWORD', '7(tI5oB}AnC0');/** MySQL 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', '');/**#@+
* 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', ')(kZG>8+ 2i),`>^8mrs~IGph#;CO66t]6-p(&mb9ZvFDV]!Mf9M%RD[q*r|Bk~9');define('SECURE_AUTH_KEY', 'X/@:>tzF{3TDezC`(/DB&f:]V684jR^ce}j8;dD:+%{Oc^mOeA~!B>77aBQ&#~_Q');define('LOGGED_IN_KEY', '66PKxbnI{M-YB8Uo,}X<rkPL4;jM[4>pl$4YTT%~{m>86zu3ndO6LNy<(?!Rf8[:');define('NONCE_KEY', 'Yk !q$JdS4]C9 o]v{3b0c<;sBzfpJYI 06ZX`-4H, eILmCm8Y6N`+zBDU*}56e');define('AUTH_SALT', 'h9}yVVDOjk]F:,4Kg]XA4!aW]6FPZy,74H72r{hQ0F}`+6#a#m?)5+3f7 ar}g(!');define('SECURE_AUTH_SALT', 'LWDotl!zBnw3$wJg!k*LRs/$^L|,d}pVc-.ax_kB7p!}Q)BUx=Y{kEnE7t}5.Po,');define('LOGGED_IN_SALT', 'C8YFR{>%P;$JjDe^V5L[9qcM}2pQ2_U&|;jFJpDZ$I}98y)P4M0w/|(Y^AlrDH1i');define('NONCE_SALT', 'g[ B^k=Vtu~AkjgVAW+)$s^1nY2MzX8sQ>d0$LqC.(Cq~,K(mHo%0xLBlLh4w2]}');/**#@-*//**
* 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 = 'nhg856_';
进入全屏模式 退出全屏模式
**方法5:**在WordPress中设置正确的目录和文件权限
在您的 wordpress 根目录中,所有文件都应具有 0644 权限,目录应具有 0755 权限。
方法 6: 更新 WordPress 中的永久链接
登录到您的 wordpress 仪表板并转到设置 -> 永久链接。检查通用设置中的帖子名称选项,然后单击保存更改。
实施上述方法之一后,请清除浏览器缓存并再次打开您的网站。现在 wordpress 中禁止的错误 403 将不再显示。