本地环境是采用xmapp架设。开启Apache的虚拟主机功能,在htdocs下创建不同文件夹,并为其配置不同的本地域名。配置完成后可以使用【自定义域名.自定义后缀】这种形式访问这些文件夹下的网站。这样在本地调试多个网站将方便很多。
以自定义域名a.myhost 并指向htdocs\a文件夹为例:
步骤
1、在c:\windows\system32\drivers\etc\
目录中打开文件 hosts
,
进行如下修改:
127.0.0.1 localhost
::1 localhost
127.0.0.1 a.myhost #添加这一条
2、在Apache的程序目录中找到 \conf\extra
,打开文件 httpd-vhosts.conf
,进行如下修改:
NameVirtualHost *:80 #去掉前面的'#'号。
# 在文件末尾添加下面的代码
<VirtualHost *:80>
DocumentRoot "/xampp/htdocs/a" #引号内用硬盘路径指向你的网站文件夹
ServerName a.myhost #a.myhost就是要自定义的域名,可随意。
</VirtualHost>
3、现在在浏览器中用 a.myhost 就可以访问 htdocs\a 文件夹中的网站。
出现Internal Server Error错误的解决办法
如果出现以下错误信息:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at master@localhost to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
是因为rewrite重定向的错误。
在 htdocs\a 文件夹下找到或创建.htaccess
文件,写入rewrite规则如下:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /a/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php/$1 [NC,L,QSA]
</IfModule>
然后在xampp控制面板,点击Apache后面的Config按钮 -> httpd.conf。
找到LoadModule rewrite_module modules/mod_rewrite.so
这句,删掉前面的'#'号。
即可。