一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

Apache配置虚拟主机及开启rewrite模式

时间:2014-12-05 编辑:简简单单 来源:一聚教程网

Apache配置虚拟主机

修改httpd.conf

启用Virtual hosts
#Include conf/extra/httpd-vhosts.conf (查找这行,把前面的#去掉)

注释 DocumentRoot "D:/Program Files/Apache/Apache2.2/htdocs"

注释

#
#    Options FollowSymLinks
#    AllowOverride None
#    Order deny,allow
#    Allow from all
#


配置 /conf/extra/httpd-vhosts.conf

 代码如下 复制代码
      # 第一个虚拟主机
    ServerAdmin xxx@gmail.com    # 管理员邮箱
    ServerName xxx.xx.com      # 绑定的域名
    DocumentRoot "d:/www/wordpress"      # 网站目录
    ServerAlias xxx.xxx.cn               #网站别名,可以不设置
    ErrorLog "logs/dummy-host.localhost-error.log"      #日志
    CustomLog "logs/dummy-host.localhost-access.log" common




Apache开启rewrite模式

打开Apache配置文件:Apache安装目录/conf/httpd.conf。

搜索rewrite:会找到"#LoadModule rewrite_module modules/mod_rewrite.so",将前面的“#”去掉。

搜索AllowOverride:将"AllowOverride none"改成"AllowOverride all"。注意:这个AllowOverride是在标签之内的那个。“~”为Apache的安装目录

在入口文件目录加入.htaccess文件,(如果.htaccess文件创建不了,可以到网上下一个)文件中写入重写规则。

 代码如下 复制代码
 
    RewriteEngine on 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] 




我的PHP项目的入口文件是index.php

最后重启Apache服务器

热门栏目