Let's summarize the configuration of apache's second-level domain name in windows.
Next we will use the local 127.0.0.1 for testing
Here we take www.jobs.com as an example. In the following code, jobs.com can be replaced with the domain name you want. This is just for testing.
Our goal is that different subdomain names can access websites under different directories.:
1. Enable the mod_rewrite function of apache (it must support rewriting). In httpd. conf, just find the # in front of it,
Then, enable the apache Virtual Host and locate the previous # in httpd. conf.
2. Add several domain names. In the C: \ WINDOWS \ system32 \ drivers \ etc directory, find the hosts file notepad to open it and add the following three domain names.
127.0.0.1 www.jobs.com
127.0.0.1 jobs.com
127.0.0.1 news.jobs.com
3. Enter the relevant code in the VM to allow it to access the www directory, find the file in the directory Apache2 \ conf \ extra, and open the code to add the following
Then, bind www.jobs.com to the directory where the relevant jobs project is located and add the following code:
After the restart, restart apache. If an apache startup error occurs after the restart, view the apache Error Log and modify the log as needed.
4. Create a file in the jobs directory and add the following code to it:
I want to bind news.jobs.com to the new directory, so not only do I need to place the. htaccess file in the root directory,
You also need to place the. htaccess file in the new directory. The. htaccess file in the new directory is written as follows:
RewriteEngine On
RewriteBase/
RewriteCond % {REQUEST_FILENAME }! -F
RewriteCond % {REQUEST_FILENAME }! -D
ErrorDocument 403/404 .htm
ErrorDocument 404/404 .htm
After everything is done, you can try www.jobs.com job.com news.jobs.com and other accesses to see the expected results.
If you need access from other second-level domain names, repeat steps 2 and 4 in the preceding method. You do not need to restart apache.
This article only applies to the test environment and verifies the security. Please use it in the product after everything is set.