×

yii2去掉index.php

yii2去掉index.php(index怎么删除)

admin admin 发表于2023-03-24 21:38:08 浏览62 评论0

抢沙发发表评论

本文目录一览:

如何去掉index.php目录

apache去掉index.php

1.编辑conf/httpd.conf配置文件

#LoadModule rewrite_module modules/mod_rewrite.so 把该行前的#去掉

同时对应Directory下要配置 AllowOverride All

2.在 CI 根目录下(即在index.php,system的同级目录下)新建立一个配置文件,命名为: .htaccess 内容如下:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond $1 !^(index\.php|robots\.txt)

RewriteRule ^(.*)$ index.php/$1

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(application|modules|plugins|system|themes) index.php/$1 [L]

3.把system/application/config/config.php 中$config['index_page'] = "index.php";改为$config['index_page'] = "";-yii2去掉index.php

4.重启apache

php CI 实战教程:[9]如何去掉index.php目录

nginx去掉index.php

1.编辑nginx.conf文件

vi /usr/local/xxxxx/nginx/conf/nginx.conf

#nginx去掉index.php

location / {

rewrite ^/$ /index.php last;

#防止某些文件夹被直接访问

rewrite ^/(?!index\.php|robots\.txt|uploadedImages|resource|images|js|css|styles|static)(.*)$ /index.php/$1 last;-yii2去掉index.php

}

2.config/config.php下配置$config['index_page'] = '';

3..重启nginx

去掉默认的index方法,如图的URL配置如:

config/routes.php,配置$route['catalogues/(:any)'] = "catalogues/index/$1";

其中(:any)表示匹配所有除CI保留关键字外的内容,后面的$1为index传入的参数内容。

多个参数采用多个(:any),如两个参数的为:$route['catalogues/(:any)/(:any)'] = "catalogues/index/$1/$2";

注:route规则如果同一目录下精确配置要在模糊配置上面,否则不起作用,如:

$route['catalogues/more'] = "catalogues/more";

$route['catalogues/(:any)'] = "catalogues/index/$1";

php CI 实战教程:[9]如何去掉index.php目录

END

注意事项

route规则如果同一目录下精确配置要在模糊配置上面,否则不起作用

nginx服务器不需要.htaccess文件

网址中间的index.php怎么去掉,看了一些回答不知道怎么做,希望能回答,解决了多给分,一定的。

使用URL重写,可以使网站的URL屏蔽index.php这种不友好的网址。

假如你的web服务器端使用的是apache,那么你需要开启mod_rewrite.so模块,

为网站在apache配置文件中的Directory配置节添加如下内容,

Options FollowSymLinks

AllowOverride ALL

Order allow,deny

Allow from all

然后在网站根目录下创建一个 .htaccess 文件,内容如下

IfModule mod_rewrite.c

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]

/IfModule

就可以在网址中屏蔽index.php了

php怎么办url中的index.php去掉

为美观一些,去掉CI默认url中的index.php。分三步操作:

1.打开apache的配置文件,conf/httpd.conf :

LoadModule rewrite_module modules/mod_rewrite.so,把该行前的#去掉。

搜索 AllowOverride None(配置文件中有多处),看注释信息,将相关.htaccess的该行信息改为AllowOverride All。

2.在CI的根目录下,即在index.php,system的同级目录下,建立.htaccess,直接建立该文件名的不会成功,可以先建立记事本文件,另存为该名的文件即可。内容如下(CI手册上也有介绍):-yii2去掉index.php

RewriteEngine on

RewriteCond $1 !^(index/.php|images|robots/.txt)

RewriteRule ^(.*)$ /index.php/$1 [L]

如果文件不是在www的根目录下,例如我的是:,第三行需要改写为RewriteRule ^(.*)$ /CI/index.php/$1 [L]。

另外,我的index.php的同级目录下还有js文件夹和css文件夹,这些需要过滤除去,第二行需要改写为:RewriteCond $1 !^(index/.php|images|js|css|robots/.txt)。-yii2去掉index.php

3.将CI中配置文件(system/application/config/config.php)中$config['index_page'] = "index.php";将$config['index_page'] = ""; 。-yii2去掉index.php

ok,完成。还要记得重启apache。