Rumah  >  Artikel  >  rangka kerja php  >  yii如何去掉index.php

yii如何去掉index.php

藏色散人
藏色散人asal
2020-08-10 10:14:281962semak imbas

yii去掉index.php的方法:首先在“httpd.conf”中开启“apache-rewrite”;然后重启Apache;接着修改配置“main.php”;最后在入口文件同级目录下添加“.htaccess”文件即可。

yii如何去掉index.php

推荐:《yii教程

yii2 去掉index.php的方法

1.开启apache-rewrite

在Windows下,我们一般使用的是Administrator账号,所以启用这两项非常简单:

 

在[Apache安装目录]/conf/httpd.conf中找到

#LoadModule rewrite_module modules/mod_rewrite.so

,去掉前面的注释符号#。如果没有这行,请添加。并确认apache安装目录下的modules文件夹中是否有mod_rewrite.so这个文件。这样就启用了Mod Rewrite功能。

在[Apache安装目录]/conf/httpd.conf中找到

Options FollowSymLinks    AllowOverride None    Order deny,allow    Deny from all

“AllowOverride None
”改成“
AllowOverride All
”,

这样所有的文件夹都支持.htaccess了,或者针对指定的文件夹启用.htaccess,可以在[Apache安装目录]/conf/httpd.conf中加入Options Indexes FollowSymLinks    AllowOverride All    Order allow,deny    Allow from all这种做法一般是和虚拟主机配置在一起的,所以大多数会把上述配置代码写入[Apache安装目录]/conf/extra/httpd-vhost.conf中,这样比较清晰易于管理。

重启Apache后,就ok了。

完成上诉步骤后,在Wordpress的固定链接中使用除默认外的链接设置,Wordpress会直接在其安装目录中生成对应的.htaccess,这样就可以使用设置的链接形式了。

2.修改配置main.php

'urlManager'=>[
'enablePrettyUrl' => true,
'showScriptName' => false,
//路由管理
'rules' => [
"<module:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>"=>"<module>/<controller>/<action>",
"<controller:\w+>/<action:\w+>/<id:\d+>"=>"<controller>/<action>",
"<controller:\w+>/<action:\w+>"=>"<controller>/<action>",
],
],

3.在入口文件同级目录下添加.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:win环境下如何安装yii框架?Artikel seterusnya:yii怎样去掉index.php