在CodeIgniter 4中删除 /public /从URL中删除 /public /,但重定向函数仍然抛向 /public /
我将我的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,index.php文件将包含在您的URL中。
如果要删除它。
检查apache中启用了mod_rewrite扩展。
使用以下代码更新您的.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.
Check mod_rewrite extension enabled in apache.
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