WordPress.org

Ready to get started?Download WordPress

Forums

Cannot access WordPress from localhost or other PC's on LAN (6 posts)

  1. Anonymous
    Unregistered
    Posted 5 years ago #

    I have an Actiontec GT701-wg router that is preventing access to my WordPress page from any PC on the LAN

    Here's the scenario: I am using computer A to access and use my WordPress site, computer B is the server that is hosting the WordPress site, and both computers are plugged into a GT701 router, which in turn is linked to the Internet. Internet users can access the server from the outside by typing in http://www.example.com (because port forwarding is set up on the GT701). However, the GT701 will not allow me to type that address in from computer A, because the GT701 interprets such an action as a request to view the GT701'a administrative interface. Instead, I must type in the local network IP address (192.168.0.xxx) of computer B to access and use my WordPress site.

    However, this causes a problem because the "home" url is used by WordPress to create all the site's links. If the "home" url is set for http://www.example.com, I will be unable to use the site from computer A (even if I type in the local IP). If the "home" url is set for the local network IP address, Internet users will not be able to use the site.

    So, in order to add content, I have to go into the database, and change the value of the "home" field in the wp_1options table from http://www.example.com to 192.168.0.xxx. Once that is done, I can add my content, but nobody on the Internet can see my blog until I change the value of "home" back to http://www.example.com.

    Thanks,
    Hackhound

  2. ClaytonJames
    Member
    Posted 5 years ago #

    I have encountered the same behavior while using Linksys routing devices on a couple if different networks. My Netgear routers, on the other hand, don't seem to care if you are inside the network or not. I think you might be able to circumvent the issue by adding your wordpress URL
    ( www.example.com ) to the hosts file (on the server). That way, when you type your blog address in the browsers address bar, it will allow the browser (on the server only, I believe) to resolve to 127.0.0.1. I know it's kind of strange to work on your blog from the server, but it's a work around that might allow you to work from inside your network until you find a suitable solution. I hope I explained that correctly.

  3. Anonymous
    Unregistered
    Posted 5 years ago #

    I tried the hosts workaround, and no matter what I try, WordPress wants to insert it's address in the browser. I did some digging around, and I found someone who had the same issue with Drupal, and they were able to modify the php code in one of the files as follows:

    In other words, base_url has to be different for internal network users and Internet users. To do this, replace the line $base_url = "http://www.yourdomain.com"; with the following PHP code:

    <?php
        $ipaddress = getenv(REMOTE_ADDR);
        $local= strpos($ipaddress, '192.168.');
           if ( $local=== false ) {
              $base_url = "http://www.yourdomain.com";
           } else {
              $base_url = "local network IP address";
           }
    ?>

    I understand what they are doing, but I am not sure if the same thing can be done with WordPress or not. And if so, which file(s) would I need to modify?

  4. ClaytonJames
    Member
    Posted 5 years ago #

    I just verified the hosts file method on one of my (Linux) servers. I accessed the blog from the servers browser, no problem. The browser address bar did indeed reflect the "http://" with the full blog address, but it resolved to 127.0.0.1. I know it did, because I unplugged the network cable. I added one line to hosts:

    127.0.0.1 "www.myblogaddress.com" (without quotes of course).

    I would assume that it should work on a Windows server as well. Perhaps two entries to be safe:

    127.0.0.1 "www.myblogaddress.com"
    127.0.0.1 "myblogaddress.com"

    I'm afraid I'm totally lost when it comes to the php method you refer to.

    Best of luck to you.

  5. Anonymous
    Unregistered
    Posted 5 years ago #

    Ahh. I got it working now - had to have the www in order for it to work. I am still hoping someone else is able to figure out the php code solution. Thanks for the help.

  6. ClaytonJames
    Member
    Posted 5 years ago #

    Glad to help...

Topic Closed

This topic has been closed to new replies.

About this Topic