欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

yii2 配置apache

程序员文章站 2022-05-08 19:21:36
...

Apache VirtualHost

担心大家不使用nginx,这里把apache 虚拟主机的配置也整理出来,像我这么负责的人不多了:)

方法一

直接在apache 虚拟主机中配置rewrite规则

<VirtualHost *:80>
    ServerName rbac.yii.local.com
    DocumentRoot /home/www/yii/rbac/web
    <Directory "/home/www/yii/rbac/web">
        Require all granted
        Allow from all
        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . index.php
    </Directory>
</VirtualHost>

方法二

rewrite规则通过.htaccess文件实现

<VirtualHost *:8000>
    ServerName rbac.yii.local.com
    DocumentRoot /home/www/yii/rbac/web
</VirtualHost>

.htaccess 内容如下(在代码web文件下已有此文件)

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php
相关标签: yii