drsxzut183207938 2017-03-30 17:30
浏览 28
已采纳

XAMPP相对URL工作在WordPress主页但不是页面

I have a testing site at tektonpress.piconmedia.com that is working correctly.

I'm having some problems with relative URLs and images on a local version.

I installed XAMPP, restored a copy of the database to my local machine, and copied FTP files over. After updating wp-config.php, just about everything is working correctly. That includes images that use relative URLs in my stylesheets.

My problem is with some images that I try to load through HTML. They display correctly on the home page, but not from other pages.

For example, the following HTML works on localhost/tektonpress/ but not localhost/tektonpress/editing/:

<img src="resources/img/logo-white.png" alt="Tekton Press logo">

Here's an example when the image doesn't work:

Example from page

The image in question is located at C:\xampp\htdocs\tektonpressesources\img\logo-white.png

When I hover over the URL while inspecting the element in Chrome, here's what I see:

One layer too deep

I tried adding a slash to the front of the path, like so:

<img src="/resources/img/logo-white.png" alt="Tekton Press logo">

Unfortunately, the page ends up looking for the image at /localhost/resources/img/logo-white.png.

I've spent several hours on this with no luck. I thought I'd finally found a simple (but potentially maintenance-heavy) solution at stackoverflow.com/questions/7823260/xampp-relative-urls-not-working-correctly, but just ended up with a server error.

Here's the contents of my .htaccess file:

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /tektonpress/

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /tektonpress/index.php [L]

</IfModule>

Any suggestions?

  • 写回答

2条回答 默认 最新

  • doupapin172773 2017-03-30 17:53
    关注

    Try using get_template_directory_uri().'/resources/img/logo-white.png'

    It should work. As I am assuming resources is in the base of your theme directory.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧