I managed to do it myself. You can do this, but you will need to install a DNS server.
Note. I decided to use .dev as my local domain, so in the following examples, the dev part will refer to my selected domain. Keep it in mind.
Install and configure a DNS server
It doesn’t matter what it is, but you need to know how to configure it correctly. The configuration depends on which DNS server you have selected. I went to dnsmasq . It is lightweight and very comfortable.
An important note for Ubuntu users is that with Ubuntu 11.10 there is already a light version called dnsmasq-base installed that will cause conflicts during installation. I will not explain here how to get around this because there are many instructions available in other places.
Once you have your DNS server installed, you must configure it to listen on an address equal to your desired domain.
In my case with dnsmasq, this meant opening /etc/dnsmasq.conf and changing line # 62 to this: address=/dev/127.0.1.1
Web server setup
Assuming you already have some kind of server software, you need to make a few settings.
First, you must edit the hosts to map the domain to your local host.
in my case, XAMPP for Linux on Ubuntu, that means I opened /etc/hosts and changed lines
127.0.0.1 localhost 127.0.1.1 tomica-ubuntu
to
127.0.0.1 localhost 127.0.1.1 tomica-ubuntu dev
This will redirect http://dev to my local server.
Then create a new virtual host with a few specific parameters, for example:
In my case, this means opening /opt/lampp/etc/extra/httpd-vhosts.conf and adding this at the end of the file:
<VirtualHost *:80> DocumentRoot "/opt/lampp/htdocs/dev" ServerName dev ServerAlias *.dev <Directory /opt/lampp/htdocs/dev> AllowOverride All </Directory> </VirtualHost>
For brevity, I will not explain this piece of code, since documentation is also available.
After that, start your DNS and web servers or restart them if they are already running.
Configure .htaccess
Open the root folder of your newly created node. This is a folder developed in yours. In my case, this is /opt/lampp/htdocs/dev . There, create a .htaccess file and put it in it:
# Specify order of index files; if none exist, show files list DirectoryIndex index.php index.html
Again, an explanation of all this will require too much space and time. Just copy / paste and don’t worry :) But do not forget to change my dev to everything that you have chosen for your domain name.
AND THIS IS THIS! . Now you can view your project using addresses such as http://folder.dev/ , http://www.folder.dev , http://folder.dev/file.html , http://folder.dev/subfolder/document.txt etc.
As a bonus, I will add one more tip. The reason I did all this is because I could more easily develop my Laravel and WordPress projects. However, with Laravel, you must redirect the URL http://lvproject.dev/ to the location /lvproject/public . And here is the .htaccess file that allows just that. Open the /lvproject folder, create a .htaccess file and put this code in it:
RewriteBase /lvproject/ RewriteCond %{REQUEST_URI} lvproject/index\.php [NC] RewriteRule index\.php(.*)$ public/ [L]
Two drawbacks of this solution: 1) the RewriteBase rule must be reinstalled for each new project (i.e. you need to manually create .htaccess in each new project); 2) Your project will be available both from http://lvproject.dev/ and http://lvproject.dev/public/ , which is not cool, but now I'm too lazy to fix it :)