2017-03-30 17:30 阅读 28


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]


Any suggestions?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    doupapin172773 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.

    点赞 评论 复制链接分享
  • dongtang7347 dongtang7347 2017-03-30 17:36

    I realize it is not much of a fix, but have you tried:

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

    Should let you pull the image properly.

    点赞 评论 复制链接分享