WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] URL discrepancy between localhost and live (5 posts)

  1. pszeinert
    Member
    Posted 4 years ago #

    I use a PHP IDE (Eclipse) for quick renderings of my site.

    My local files are stored at http://localhost/problemsit

    My live files are stored at http://problemsite.domainname.com

    The live site is set up as a sub-domain, but can also be typed http://www.domain.com/problemsite

    The problem is that when I define images, for example background in the imported CSS files, I can successfully load them using /wp-content/themes/thematic/library/imgs/file.gif

    ...however, on my local computer, the files will not resolve unless I absolutely link it as http://localhost/problemsite/wp-content/themes/thematic/library/imgs/file.gif

    I have tried any number of periods before the file and have scoured many sites before coming here. I even tried adding this snippet:

    define('WP_HOME', 'http://'.$_SERVER['HTTP_HOST'].'/problemsite');
    define('WP_SITEURL', 'http://'.$_SERVER['HTTP_HOST'].'/problemsite');

    to the wp-config.php file, but to no avail.

    This is the first problem I have encountered that I have not been able to find a resolution for.

    Re-formatted post for clarity

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    Do not use relative urls in a WordPress install. Stick to full, absolute, urls.

  3. pszeinert
    Member
    Posted 4 years ago #

    Do not use relative urls in a WordPress install. Stick to full, absolute, urls.

    That would explain my trouble finding a solution. After researching the logic behind using absolute URLs, I understand and completely agree.

    For a follow up question, is there a bit of PHP such as an "if" statement that could swap strings depending on the location of the files?

    i.e. http://localhost/problemsite vs. http://problemsite.domainname.com

  4. esmi
    Forum Moderator
    Posted 4 years ago #

    Not that I know of but you could have a look at the Search & Replace plugin: http://wordpress.org/extend/plugins/search-and-replace/

  5. pszeinert
    Member
    Posted 4 years ago #

    Yeah, search and replace is what I have done in the past. I would like to keep up to date copies on both my testing server and live server. Ideally, they would be two identical code bases in two different locations.

    I guess I can consider this resolved, but I will post a solution if I can develop one. To be honest, I think I have used a similar statement for another project.

Topic Closed

This topic has been closed to new replies.

About this Topic