【发布时间】:2017-04-27 12:20:47
【问题描述】:
我从需要工作的服务器上复制了一个 wordpress 站点,并将其设置在 localhost 上,wordpress 文件夹设置为 root 的子目录。
我唯一的问题是我的链接重定向到根目录而不是 wpfolder,例如。并且文件路径中没有 wpfolder 名称。
例子:
ht.p://localhost/wpfolder/wp-content/themes/tbt/_inc/js/functions.js
应该是:
ht.p://localhost/root/wpfolder/wp-content/themes/tbt/_inc/js/functions.js
我已遵循 codex https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory#Using_a_pre-existing_subdirectory_install 中的所有说明,并且一切正常,除了我一直在努力让我的链接和文件重定向到正确的文件路径。
我已按此顺序保存了常规设置、刷新了永久链接并重新启动了服务器。我还确认正在读取 htaccess 并且正在读取数据库,并且 wp-admin 中的所有帖子都可以正常读取。
令人困惑的是,即使服务器上的原始站点在子目录中安装了 wp,我也看不到它是如何重定向的。本地副本的站点结构如下:
/localhost/site_root/wpfolder
和原创:
user@domain/public_html/wpfolder
导出数据库时我设置的地址如下:
网站地址
远程://www.domain.com,
local: //localhost/siteroot/
WP 地址 远程:/home/siteuser/public_html, 本地:/siteroot/wpfolder (我不明白为什么这不指向原始站点上的子目录?)
远程根目录下的htaccess:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} /order-online/order-now/
RewriteRule ^(.*)$ https://www.sitename.com.au/order-online/order-now/$1 [R,L]
# 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
在迁移数据库并在 wp-admin 中保存所有设置后自动写入根目录下的本地 htaccess:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} /order-online/order-now/
RewriteRule ^(.*)$ https://www.originalsitedomain.com/order-online/order-now/$1 [R,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /siteroot/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /siteroot/index.php [L]
</IfModule>
# END WordPress
我在根目录下的本地 index.php(与远程相同):
require( dirname( __FILE__ ) . '/wpfolder/wp-blog-header.php' );
例如,目前不是我的链接将我带到 localhost/site_root/link 而是转到 localhost/link 和 404'ing。
由于我不完全理解,我无法让它工作:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^localhost/siteroot$
RewriteCond %{REQUEST_URI} !^/wpfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wpfolder/$1
RewriteCond %{HTTP_HOST} ^localhost/siteroot$
RewriteRule ^(/)?$ wpfolder/index.php [L]
</IfModule>
但无论如何它不在原始站点的 htaccess 中(为什么我不明白)。我对 jeebus 的爱完全没有想法,谁能帮助上面的重写或建议我可能做错了什么?
如果我可以提供更多信息,请告诉我。
谢谢。
编辑:如果我只是复制原始站点,我无法理解为什么会出现问题! N一个原始链接或url都以根文件夹为前缀。
EDIT2:404 的一些示例 html。仅显示标题(由于require( dirname( __FILE__ ) . '/wpfolder/wp-blog-header.php' ))。
header.php
if (!is_404() && $ie7==false && !isset($_GET['preview'])) {
echo '<script src="/tbtwp/wp-content/themes/tbt/_inc/js/functions.js"></script>';
}
菜单:
<div class="menu">
<ul>
<li class="nav-home <?php if(is_front_page()){ echo 'current_page_item' ; }?>"><a tabindex="1" href="/" title="home">Home</a></li>
<li class="nav-about-us"><a tabindex="1" href="/about-us/" title="about-us">About Us</a></li>
<li class="nav-the-store"><a tabindex="1" href="/the-store/" title="the-store">The Store</a></li>
<li class="nav-catering"><a tabindex="1" href="/catering/" title="catering">Catering</a></li>
<li class="nav-order-online <?php if(is_page('order-online/order-now')){ echo 'current_page_item' ; }?>"><a tabindex="1" href="/order-online/" title="order-online">Order Online</a></li>
<li class="nav-our-stories"><a tabindex="1" href="/our-stories/" title="our-stories">Our Stories</a></li>
<li class="nav-contact"><a tabindex="1" href="/contact/" title="contact">Contact</a></li>
</ul>
</div>
【问题讨论】:
-
是否有任何链接有效或所有链接都已损坏?我建议使用interconnect/it PHP database search and replace tool(无从属关系)在 url 分片上运行序列化搜索和替换
-
所有链接都转到根 localhost/link 而不是 localhost/root/link。我现在看看你的链接。
-
我认为这不是问题,因为 dbmigrate 在我导出数据库时会处理这个问题。当我的本地站点解析为 localhost/page.php (404) 而不是 localhost/sitefolder/page.php 时,它更多的问题是为什么远程站点会解析为 www.domain.com/page.php
-
啊,@JPB 我一定看过你说的地方
导出数据库时我设置的地址如下:
-
好吧,如果它是一个自定义主题,并且开发人员正在使用类似 Roots Soil Root Relative URLs github.com/roots/soil(作为插件或直接在 functons.php 中),这肯定会影响您的网站。