Codeigniter 4:无法使用apache mode_rewrite访问页面

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeigniter 4:无法使用apache mode_rewrite访问页面相关的知识,希望对你有一定的参考价值。

我使用Wampserver在本地计算机上安装了Codeigniter 4.0.0.rc3,并创建了一个'people'控制器。我可以使用以下地址访问该页面:

http://127.0.0.1/election/index.php/people

但并非没有'index.php':

http://127.0.0.1/election/people

这是错误:

在此服务器上找不到请求的URL /Projects/Web/election/public/index.php/people。

。htaccess在公共目录中,并且正在工作,因为该错误在路径中显示index.php。

这是我的htaccess:

# Disable directory browsing
Options All -Indexes

# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------

# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # If you installed CodeIgniter in a subfolder, you will need to
    # change the following line to match the subfolder you need.
    # http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
    # RewriteBase /

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Rewrite "www.example.com -> example.com"
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
    RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

    # Checks to see if the user is attempting to access a valid file,
    # such as an image or css document, if this isn't true it sends the
    # request to the front controller, index.php
    RewriteCond $1 !^(index.php|assets|robots.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]

    # Ensure Authorization header is passed along
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    ErrorDocument 404 index.php
</IfModule>

# Disable server signature start
    ServerSignature Off
# Disable server signature end
答案

在linux apache2中,以下工作也应适用于wampp的apache:

  1. 确保已启用mode_rewrite
  2. 编辑您的公共.htaccess文件:

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

to

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

((如果有人解释QSA声明,将不胜感激)

  1. 在app / Config / App.php中编辑:

    public $ indexPage ='index.php';

to

public $indexPage = '';

以上是关于Codeigniter 4:无法使用apache mode_rewrite访问页面的主要内容,如果未能解决你的问题,请参考以下文章

Codeigniter 4:无法解密加密的帖子数据

无法从 codeigniter 2.1.4 连接到 SQL Server 2012

Codeigniter 4 cookie问题无法设置

在 CodeIgniter 4 中提交表单后重定向页面无法工作

CodeIgniter 4 ... documentRoot不在公共环境中……htaccess无法正常工作

如何在 apache 2.2 版本上运行文件 codeigniter [重复]