Codeigniter 4:无法使用apache mode_rewrite访问页面 [英] Codeigniter 4: Cannot access the page with apache mode_rewrite

查看:37
本文介绍了Codeigniter 4:无法使用apache mode_rewrite访问页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I installed Codeigniter 4.0.0.rc3 on my local computer using Wampserver and created a 'people' controller. I can access the page using this address:

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

但并非没有'index.php':

But not without 'index.php':

http://127.0.0.1/election/people

这是错误:

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

The requested URL /Projects/Web/election/public/index.php/people was not found on this server.

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

这是我的htaccess:

This is my 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

更新:此htacces在Linux主机上可以正常运行,但在Windows 10上不能与Wampserver一起使用

UPDATE: This htacces is working perfectly on a Linux Host but not working with Wampserver on Windows 10

推荐答案

在弄清楚之前,我不得不花很多时间玩,但是我已经在一个子文件夹中安装了CodeIgniter.(我通过 http://127.0.0.1/myapp/访问该网站).

I had to play around a lot before I figured it out, but I had installed CodeIgniter in a subfolder. (I access the website via http://127.0.0.1/myapp/).

我已经在配置文件中配置了$ baseURL参数,但是我一直收到该Apache错误.就像您一样,如果我在URL中添加了/index.php,那么我所有的路由都可以正常工作.

I had configured the $baseURL parameter in the config file, but I kept getting that apache error. Just like you, if I added the /index.php in the URL, all my routes were working fine.

在/public/.htaccess中,"QSA"选项无济于事,但上面的这一部分做了:

In /public/.htaccess, The QSA option didn't help, but this section just above did:

#如果在子文件夹中安装了CodeIgniter,则需要#更改以下行以匹配所需的子文件夹.# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase RewriteBase/myapp/

# 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 /myapp/

添加此选项可以使mod_rewrite正常工作.显然,您需要将/myappp/更改为您的虚拟子文件夹,以使其与Config/App.php中$ baseURL参数的子文件夹部分相匹配

Adding this allow mod_rewrite to work fine. Obviously you need to change /myappp/ to what your virtual subfolder is, in order for it to match the subfolder portion of the $baseURL parameter in Config/App.php

希望这项帮助!

这篇关于Codeigniter 4:无法使用apache mode_rewrite访问页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆