0

I have installed apache2 on my computer with Linux. I can create websites in directory /var/www/html/ so for example if I create following file:

/var/www/html/mywebsite/index.php

then my site is accessible on following URL:

http://localhost/mywebsite

How can I set website alias name, when I want to use following URL for my website

http://mywebsite.com 

instead of

http://localhost/mywebsite ?

Can I set this in /var/www/html/mywebsite/.htaccess file?

(website directory /var/www/html/ is not shared on internet or any other network, it just should work on my private PC)

EDIT: It is not exactly the same problem as mentioned problem

I need not just replace domain name for IP address, but domain name with path for another domain name. I have tried to set in /etc/hosts:

<VirtualHost *:80>
   ServerName mywebsite.com

   # redirect elsewhere
   Redirect localhost/mywebsite

</VirtualHost>

I restarted my computer but this redirect doesn't work for me.

Community
  • 1
  • 1
tomas.teicher
  • 913
  • 3
  • 13
  • 26

1 Answers1

1

localhost is for things on your local computer. Every computer's local ip address is set to 127.0.0.1. So no one else on the internet can access your local computer's stuff through localhost. You would have to set your computer up as a server, with it's own ip address, or host it on a server. Then you can register a domain with a DNS, to forward requests for your domain to your server.

katerinah
  • 111
  • 4
  • thanks, I just added notice to my question. The redirection from localhost/mywebsite to mywebsite.com should work only on my computer. Whole website directory is only on my PC, it is just my personal work, not accessible from outside of my computer. – tomas.teicher Aug 22 '14 at 19:54
  • 1
    Then maybe you just have to somehow trick your own DNS server into recognizing and forwarding the name to localhost? – katerinah Aug 23 '14 at 23:30