Codeigniter 4 删除去掉index.php,Codeigniter 4 remove index.php

Only Apache Web Server / 只适合Apache服务器

 

https://codeigniter4.github.io/CodeIgniter4/installation/running.html#hosting-with-apache

 

Open httpd.conf

打开httpd.conf文件

1、Make sure that the rewrite module is enabled (uncommented)

去掉下面代码前面的#号,

LoadModule rewrite_module modules/mod_rewrite.so

2、make sure that the default document root’s <Directory> element enables this too

将默认路径下的  AllowOverride None 改为All

AllowOverride All

 

Save and restart the Apache server

保存,并重启Apache服务器

 

3、Open public/.htaccess

打开public/.htaccess

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Add ? after index.php

在index.php后面添加  ?

 

It’s successful now.

这样基本上就可以去掉URL中的index.php了

Other considerations

其他注意事项

 

1、app/Config/App.php

public $baseURL = 'http://simple.com/';

 

2、Do not create a .htaccess file like Codeigniter 3 to remove index.php in URL

注意,不要在根目录下创建.htaccess来去掉URL中的index.php,这是Codeigniter3的方法

 

 

原创文章,转载请注明出处

https://www.ponote.com/article/68473

 

Like
喜欢 哈哈 哇哦 悲伤 愤怒
21

评论 0