加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Codeigniter – .htaccess给出404页面找不到(文件在子文

发布时间:2020-12-13 13:12:24 所属栏目:PHP教程 来源:网络整理
导读:当我上传文件时,我将它们上传到共享主机中.问题是我的codeigniter的文件和文件夹位于其中一个网站名称文件夹中. 当我访问该网站时,它给我一个404错误. 我的.htaccesss文件: IfModule mod_rewrite.c RewriteEngine On RewriteBase / #Removes access to the
当我上传文件时,我将它们上传到共享主机中.问题是我的codeigniter的文件和文件夹位于其中一个网站名称文件夹中.

当我访问该网站时,它给我一个404错误.

我的.htaccesss文件:

<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>
     ErrorDocument 404 index.php
</IfModule>

我真的不知道该怎么办.任何帮助都是有用的.谢谢.

编辑:当我编辑index.php文件时,只需输入echo’Hey’;并删除.htaccess文件,它工作正常.

根据您的文件结构:

404错误可能与此部分有关:

<IfModule !mod_rewrite.c>
     ErrorDocument 404 index.php
</IfModule>

这意味着:如果没有使用或不存在Apache模块mod_rewrite.c,那么所有404都将被发送到index.php.如果您的codeigniter index.php位于根“web”文件夹(public_html)中,那么您应该编写ErrorDocument 404 /index.php.如果它在您需要的任何子文件夹中,例如:/dyar.no/index.php,其余规则也应指向相同的index.php.
如果您将它放在index.php(您网站的根文件夹的同一文件夹)附近,那么您当前的.htaccess可以正常工作.

此外,如果你没有有意义的条件和规则,.htaccess是没用的.你拥有的那个是专门用于codeigniter的,它有一个系统和一个应用程序文件夹.

您可以在其他网站的文件夹中包含多个.htaccess文件(如果您在多个文件夹中使用codeigniter,请将.htaccess复制到这些子文件夹,例如:如果dyar.no使用的是codeigniter副本.htaccess到那个文件夹).

我的建议

我注意到你也在使用Wordpress,因此可以相应地更改这些规则…所以删除你当前的根.htaccess文件(来自public_html文件夹)并在你的wordpress网站安装BulletProof Security插件.完成后,在管理仪表板(BPS选项卡)中,您只需单击生成安全.htaccess(它会根据您的文件结构生成强大的.htaccess,并将涵盖大多数安全问题).之后,在根文件夹和管理文件夹上激活它,你应该完全覆盖它.

生成的.htaccess也可以很好地引用你可能需要的其他.htaccess.

http://www.askapache.com/htaccess/htaccess.html是我发现理解和写作.htaccess和here are a few examples的最佳参考之一.

希望能帮助到你!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读