Rumah  >  Artikel  >  rangka kerja php  >  yii怎样去掉index.php

yii怎样去掉index.php

王林
王林asal
2020-08-15 15:18:283749semak imbas

yii去掉index.php的方法:1、开启apache的mod_rewrite模块,并重启apache;2、编辑项目中的/config/web.php文件;3、在与index.php文件同级目录下添加【.htaccess】文件。

yii怎样去掉index.php

具体方法:

(推荐教程:php图文教程

1、开启apache的mod_rewrite模块

  • 去掉LoadModule rewrite_module modules/mod_rewrite.so前的“#”符号

  • 确保DocumentRoot "/Library/WebServer/Documents"b7d5df3f97e337c3e309ffe7805edc47bb15ed4aadeed04b3991578461de0768中有“AllowOverride All”

  • 重启apache,命令: sudo apachectl restart

2、在项目中的/config/web.php中添加代码:

components'=>array(            
  ...
'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                &#39;<controller:\w+>/<action:\w+>&#39;=>&#39;<controller>/<action>&#39;,
            ],
        ],           
 )

(视频教程推荐:php视频教程

3、在与index.php文件同级目录下(/web/)添加文件“.htaccess”,内容如下:

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

Atas ialah kandungan terperinci yii怎样去掉index.php. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel sebelumnya:yii如何去掉index.phpArtikel seterusnya:yii2如何隐藏index.php