为本地Apache下的不同文件夹配置独立域名

本地环境是采用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这句,删掉前面的'#'号。

即可。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值