现代控制器上的代码指示器404 [英] codeigniter 404 on existing controller

查看:66
本文介绍了现代控制器上的代码指示器404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我尝试访问我的网站的视频页面时,它会重定向到404.shtml页面。但是cvideos.php文件存在于我的控制器文件夹中。



如果我这样访问 http:// domain-name / videos ,那么它将被重定向为
//domain-name/500.shtml



如果我访问相同的网页,像这样// domain-name / videos / myvideos,那么它将被重定向像这样
//domain-name/404.shtml



此外,如果我更改控制器名称从视频到一些其他名称,如videoss它工作正常。任何人都可以告诉wats这个问题。



我在我的.htaccess中使用这行也只是为了测试。但没有用。



RewriteRule ^ videos / $ index.php / videoss / [L]

方案

您的控制器需要与其包含的类相同。



因此 -


$ b b

 <?php 

控制器视频扩展控制器{

/ * bla * /
}

?>

应另存为:





code> videos.php

也是你的重写规则有两个s,但这可能是有意的。



,它看起来像你想要做的.htaccess可以通过CI的路由






编辑:.htaccess

 < IfModule mod_rewrite.c> 
RewriteEngine On
RewriteBase /

#Removes用户访问系统文件夹。
#另外,这将允许您创建一个System.php控制器,
#previously这是不可能的。
#'system'可以替换,如果你已经重命名您的系统文件夹。
RewriteCond%{REQUEST_URI} ^ system。*
RewriteRule ^(。*)$ /index.php?/$1 [L]

#当您的应用程序文件夹不是在系统文件夹
#此代码段阻止用户访问应用程序文件夹
#提交者:Fabdrol
#Rename'application'到您的应用程序文件夹名称。
RewriteCond%{REQUEST_URI} ^ application。*
RewriteRule ^(。*)$ /index.php?/$1 [L]

#检查用户是否尝试访问一个有效的文件
#s如一个图像或CSS文档,如果这不是真的,它发送
#request到index.php
RewriteCond%{REQUEST_FILENAME}! - f
RewriteCond%{REQUEST_FILENAME}!-d
RewriteRule ^(。*)$ index.php?/ $ 1 [L]
< / IfModule>

< IfModule!mod_rewrite.c>
#如果我们没有安装mod_rewrite,所有404的
#都可以发送到index.php,一切正常。
#提交者:ElliotHaughin

ErrorDocument 404 /index.php
< / IfModule>

请注意,我没有创建 - 通过CI论坛搜索。



不要忘记在配置中将index.php的值设置为。


I am facing a different problem in codeigniter.

When I try to access the videos page in my site, it will redirect to 404.shtml page. But cvideos.php file exists in my controllers folder.

If I access like this http://domain-name/videos , then it will be redirected like this //domain-name/500.shtml

And If I access the same page like this //domain-name/videos/myvideos, then then it will be redirected like this //domain-name/404.shtml

Also, If I change the controller name from videos to some other name like videoss it works fine. Can anyone tell wats the issue.

I used this line in my .htaccess also just for testing. But no use.

RewriteRule ^videos/$ index.php/videoss/ [L]

解决方案

Your controller needs to be the same name as the class it contains.

hence -

<?php

controller Videos extends Controller {

 /* bla */
}

?>

should be saved as:

videos.php in the "controllers" directory.

Nothing else will work.

also your rewrite rule has two "s"'s, but that might be intentional.

and it looks like what you are trying to do with .htaccess can be achieved with CI's routing


Edit: .htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [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 index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</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.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>  

please note I did not create this - it was found by scouring the CI forums. It's a rather thorough htaccess however.

Don't forget to set the value of "index.php" to "" in your config.

这篇关于现代控制器上的代码指示器404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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