【问题标题】:XAMMP Wordpress installation can't find pictures/filesXAMPP Wordpress 安装找不到图片/文件
【发布时间】:2016-11-09 19:18:22
【问题描述】:

我已将我的网站克隆到 xampp 以获取本地版本。我的 WordPress 站点位于 C:/xampp/htdocs/my-website。

我还将我的数据库克隆到本地,并将网址从网络更改为http://localhost/my-website

我已经制作了一个 .htaccess 文件,并且已经在 httpd.conf 中设置了 xampp 覆盖所有文件,该文件不会被忽略。

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /my-website/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /my-website/index.php [L]
</IfModule>
# END WordPress

我可以通过http://localhost/my-website 看到我的网站,但我的所有 .js、.css、.png 等文件都找不到。我从 Firefox 中查看了网络分析,链接不完整。

这是错误的链接:

http://localhost/wp-content/themes/storefront/startseite.js

但它应该是这样的:

http://localhost/my-website/wp-content/themes/storefront/startseite.js

我在谷歌上搜索了很多,但找不到解决方案。希望你知道答案。

谢谢大家!

【问题讨论】:

  • 有人知道答案吗?

标签: javascript php wordpress apache .htaccess


【解决方案1】:

将网页上的网址更改为http://localhost/my-website....

你是怎么做到的?在 wp_options?还是外观>>常规设置?

您应该使用interconnectit.com WordPress Serialized PHP Search Replace Tool 更改数据库选项和帖子/页面内容中的所有 URL。该工具将正确更改所有 URL,并且还可以正确处理数据库中的序列化数据。

并且,在您移动 WordPress 网站的目录或文件夹后,请在“设置”>“永久链接”中重新保存永久链接。这会将正确的永久链接写入 .htaccess。

另见Moving WordPress « WordPress Codex

【讨论】:

  • 我已经在我的数据库和常规设置中使用了搜索和替换工具。我还重新保存了我的永久链接。但是网址仍然是错误的。在我的 php 文件中,我例如写:&lt;script type="text/javascript" src="/wp-content/themes/storefront/styleswitcher.js"&gt;&lt;/script&gt; 但我网站上的输出是 http://localhost/wp-content/themes/storefront/styleswitcher.js 但它应该看起来像 http://localhost/my-website/wp-content/themes/storefront/styleswitcher.js
  • 您在 .htaccess 中的永久链接块可能不正确。最好的办法是从 WP 后端重新保存永久链接,以便 WP 可以正确编写它们。
  • 但是如果没有 htaccess 文件以及我从问题顶部输入的条目,我无法打开后端,因为 xampp 不会在没有它的情况下重定向到我的网站
  • 我尝试使用旧的 htaccess 进入 wp-admin。比删除内容并保存永久链接。 Wordpress 用完全相同的条目编写了一个新的 htaccess,但问题仍然存在
【解决方案2】:

我找到了解决方案。我必须为我的网站制作一个虚拟主机。以下是您必须执行的 4 个步骤:

  1. 转到 C:\xampp\apache\conf\extra\httpd-vhosts.conf 并创建两个新主机。首先设置一个本地主机,这样当你想调用另一个没有虚拟主机的文件夹时:

#localhost
<VirtualHost *:80>
  DocumentRoot "C:/XAMPP/htdocs"
  ServerName localhost
</VirtualHost> 
#My Website
<VirtualHost *:80>
  DocumentRoot "C:/XAMPP/htdocs/my-website" #your path to your installation
  ServerName my-website.dev #Change my-website to your wish name/url
  ServerAlias my-website.dev #Change my-website to your wish name/url
</VirtualHost>   
  1. 转到 Windows 主机文件并添加以下内容:

	127.0.0.1		my-website.dev
  1. 转到您的 Wordpress .htaccess 文件并将其粘贴到其中:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

您必须保存所有文件并重新启动 Apache 和 MySQL 服务器

  1. 现在您必须将数据库中的所有 Worpdress url 更改为 http://my.website.dev。为了简化这一步,您必须从https://interconnectit.com/products/search-and-replace-for-wordpress-databases/ 下载 PHP 中的数据库搜索和替换脚本。解压缩并将文件夹Search-Replace-DB-master 粘贴到C:/XAMPP/htdocs 中。 打开浏览器并转到此网址:http://localhost/Search-Replace-DB-master/。现在在数据库部分(数据库名称、用户、密码)中输入您的数据库信息。转到顶部并在replace 字段中输入您的旧网址(在我的情况下:https://my-website-old-url.com)和在with 之后的字段中输入您的新网址(在这种情况下:http://my-website.dev)。

现在点击页面中间的实时运行,您所有的旧网址都将被新网址替换。

最后转到浏览器并输入您的新网址:my-website.dev

就是这样!希望我能帮助别人。

【讨论】:

    猜你喜欢
    • 2016-02-24
    • 2020-05-19
    • 2012-02-25
    • 2014-03-18
    • 2017-01-13
    • 1970-01-01
    • 2011-02-19
    • 2022-10-24
    • 2016-10-12
    相关资源
    最近更新 更多