在CodeIgniter 4中删除 /public /从URL中删除 /public /,但重定向函数仍然抛向 /public /

发布于 2025-02-04 19:28:38 字数 417 浏览 4 评论 0原文

我将我的CI4项目配置更改为从URL删除 /public/index.php,之后,可以在没有该URL的情况下访问该项目。但是,如果我使用redirect() - > to('Contoller)函数重定向URL,则它仍将重定向到ProjectName/public/Controller。

例如,假设我访问“ ProjectName/Admin”(如果未登录),我应该将我重定向到“ ProjectName/Login”,但是我不是被重定向到该地址,而是将我重定向到“ ProjectName/public/login”

。通过禁用公共文件夹中的元素(重命名)的测试,并在重定向后变为404,并说

“没有找到控制器或其方法: \ app \ controllers \ public ::登录“

I changed my CI4 project configuration to remove /public/index.php from the url, and after that, the project can be accessed without that url. However, if I redirect the url using the redirect()->to('contoller) function, it still redirects to projectname/public/controller.

For example, suppose I access "projectname/admin", if not logged in, I should be redirected to "projectname/login", but instead of being redirected to that address, I was redirected to "projectname/public/login"

I did a test by disabling the element in the public folder, (renamed), and it changed to 404 after the redirect and says

"Controller or its method is not found:
\App\Controllers\Public::login"

Is there anything that would need to be changed again regarding the removal of public from the url?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与风相奔跑 2025-02-11 19:28:38

默认情况下,index.php文件将包含在您的URL中。
如果要删除它。

  1. 检查apache中启用了mod_rewrite扩展。

  2. 使用以下代码更新您的.htaccess文件。

    重新创新
    重新WritriteCond%{request_filename}!-f
    rewriteCond%{request_filename}!-d
    重写 ^(。*)$ index.php/$ 1 [l]

可以在此处找到更多信息。

https://codeigniter.com/user_guide/general/general/general/urls.html

By default, the index.php file will be included in your URLs.
If you want to remove it.

  1. Check mod_rewrite extension enabled in apache.

  2. update your .htaccess file with following code.

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

More information can be found here.

https://codeigniter.com/user_guide/general/urls.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文