1、在如下的文件中添加域名以及IP
C:WindowsSystem32driversetchosts
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 xxx.xxx.com
2、在Apache服务器配置如下
<VirtualHost *:80>
ServerName xxx.xxx.com
DocumentRoot "D:xxxxxxxxxxxx"
</VirtualHost>
3、URL地址重写修改:在windows下的Apache配置文件
<VirtualHost *:80>
ServerName api.xstudy.cn
DocumentRoot "D:xxxxxxxxxxxx"
RewriteEngine on=====》重写开启
RewriteRule ^/([0-9a-z\_]+)/([0-9a-z\_]+)/([a-z0-9\_]+).do$ /$1.php?call=$2.$3 [PT] ====》重写规则
</VirtualHost>
4、重写规则略解
实际需要输入的地址: test.php?call=test.test
想要输入的美化后的地址:test/test/test.do
^/([0-9a-z\_]+)/([0-9a-z\_]+)/([a-z0-9\_]+).do$ / $1.php?call=$2.$3 [PT]
对地址做匹配和替换
前面部分是地址栏输入的URL,$1,$2,$3代替了你在实际输入的时候输入的内容。
后面的部分是实际需要输入的URL,每一个括号匹配一个 $n。
在你输入美化后的地址,进行正则匹配,替换成为实际需要输入的地址,然后访问。