Apache开启虚拟机配置及伪静态规则

学习记录,配置Apache2.4版本支持虚拟机并启用伪静态规则。

1、修改配置文件

先编辑Apache的conf目录下的httpd.conf文件。

去除# LoadModule rewrite_module modules/mod_rewrite.so的注释,开启mod_rewrite.so模块支持。去除# Include conf/extra/httpd-vhosts.conf的注释,引入虚拟机配置文件。

编辑httpd-vhost.conf


    #发生错误时将发送邮件
    #ServerAdmin [email protected]
    #文档根目录
    DocumentRoot "E:/www"
    #域名
    ServerName www.xxx.com
    #错误日志
    ErrorLog "logs/error.log"
    #访问日志
    CustomLog "logs/access.log"
    #配置rewrite相关选项
    
        #允许所有指令,这将允许.htaccess
        AllowOverride All
        #2.2的访问控制配置,先检查允许的条件,没有允许的全部禁止,中间只能有一个逗号不能有空格
        #Order Allow,Deny
        #Allow from All
        #2.4的访问控制配置,效果等同以上
        Require all granted
    

2、修改.htaccess

#以下表示:如果存在目录或文件则直接访问,否则执行RewriteRule
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#隐藏index.php
RewriteRule ^(.*)$ index.php/$1 [L]

然后重启服务器就ok

你可能感兴趣的:(Apache/nginx)