Apache local secondary domain name configuration method

  • 2020-05-10 23:19:59
  • OfStack

This article describes the Apache local level 2 domain name configuration method. I will share it with you for your reference as follows:

When we debug web locally, we often have many different projects. For different projects, we want to use different folders and different domain names.

For example, today I was building a flower website, but a client temporarily wanted to build a simple website for selling glasses. The two websites were placed in different directories on the computer, and they needed to be visited by two different domain names. One is flower.domain.com, and one is glass.domain.com.

In general, we should do this:

1. In the local hosts file, point flower.domain.com to 127.0.0.1

2. Bind flower.domain.com in IIS or Apache and point it to the corresponding local folder;

This process is not very complicated, but we have a lot of business, and we hope to be able to implement it more easily.

Now, with this approach, no matter how many more businesses you add, all you need to do is add your folder.

From now on, you don't need to make any Settings, let alone restart any programs.

Methods:

In the Apache configuration file, add the following at the end:


rewriteengine on
rewritecond %{HTTP_HOST} [^.]+\.lvh\.me$
rewriterule ^(.+)$ %{HTTP_HOST}$1 [C]
rewriterule ^([^.]+)\.lvh\.me(.*)$ /$1$2

OK, you can use *.lvh.me to access all of your directories.

If you enter flower. lvh. me, it points to the directory is equivalent to: http: / / / flower 127.0.0.1

If you enter glass. lvh. me, it points to the directory is equivalent to: http: / / / glass 127.0.0.1

I hope this article has helped you with your Apache server setup.


Related articles: