Support » Networking WordPress » Subdomains on localhost

  • Resolved gan35h


    Because of the requirement of a site in the network called ‘blog’, I had to use sub-domains instead of subfolders. WordPress doesn’t allow a subfolder called ‘blog’.

    Anyway, so I added these changes in my hosts file:

    # site1.localhost
    # site2.localhost
    # blog.localhost

    Then I went to my httpd.conf file and added the setup for each individual subdomains for localhost:

    For site 1:
    NameVirtualHost *:80
    <VirtualHost *:80>
    ServerName localhost
    ServerAlias site1.localhost
    DocumentRoot “..\htdocs\wordpress\site1”
    DirectoryIndex index.php index.html index.html index.htm index.shtml

    and so on for site2 and blog. I am a little unsure about using * there. I think something else goes there. :/

    I went on to activate multisite in my wp-config file as:
    define(‘WP_ALLOW_MULTISITE’, true);

    But, at the end of the process I’m getting this message:

    Because you are using localhost, the sites in your WordPress network must use sub-directories. Consider using localhost.localdomain if you wish to use sub-domains.

    What must I do to get subdomains then?

    Would really appreciate your help here. Thanks!

Viewing 10 replies - 1 through 10 (of 10 total)
  • In your hosts file, change localhost to localhost.something. Or peas.corn. Or Or mytestsite.loc.

    See? 😀

    1. So I should change the site1.localhost to localhost.site1 in the hosts file? And so on?

    2. I assume I must also repeat those changes in the conf file?

    So I should change the site1.localhost to localhost.site1 in the hosts file? And so on?

    No. You’d have to change it to site1.localhost.something.

    A domain is something.something. That’s what multisite is looking for.

    subdomain.localhost throws it off, because it ads like a full domain. thus you need subdomain.localhost.whatever.

    We keep suggesting .loc because it’s easy to replace with .com/org/net when you go live 🙂

    I don’t think I’ve still got it.

    So I’ve made the following changes:

    Changed hosts file to read: localhost localhost.corn

    But does this mean that I have to install wordpress all over again? To point the new database towards this address?

    How about this as an alternative? I use sub-folders and use the word ‘blogs’ instead of ‘blog’ but while transferring the site to a web host, I use subdomains where I get to use ‘blog’ again. Would this work?

    If you’re going to export/import your sites to move them, sure.

    If you want to just pick up your files and DB to move it, you should do YOURREALDOMAIN.loc blogs.YOURREALDOMAIN.loc

    instead. Then right before you move, do a search/replace. We speak from experience. You REALLY want to use that kind of pattern. WPMUGuru can explain it better, I jut remember that it works better.

    OK, so finally going for subdomains on localhost.

    Trouble is that I’m getting stuck.

    I added local.loc in my hosts file along with its subdomains. I installed Apache with this address.

    When I type in my browser, I get the ‘It works’ message. But it tries to look for the address ‘local.loc’ on the internet, which then fails.

    I changed my httpd-vhosts.conf file also to include:

    <VirtualHost *:80>
    ServerAdmin [email address]
    DocumentRoot “../htdocs/local”
    ServerName local.loc
    ServerAlias local.loc
    DirectoryIndex index.php index.html index.html index.htm index.shtml

    Also did this for its subdomains.

    Any suggestions?

    If you’re using MAMP you have to edit /Applications/MAMP/conf/apache/httpd.conf

    <VirtualHost *>
    DocumentRoot "/Applications/MAMP/htdocs"
    ServerName ipstenu.loc

    for example

    Using Apache 2.2.19, but I added this line too. No luck 🙁

    OK, this is silly. But I deleted the hosts file and then made a new one using Notepad. AND IT WORKED! WHEW!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Subdomains on localhost’ is closed to new replies.