繁体   English   中英

Codeigniter htaccess-子文件夹中的控制器不起作用

[英]Codeigniter htaccess - controllers in subfolder not working

我是CI的新手,对重写规则了解不多。 我能够从stackoverflow帖子中找到htaccess规则,这使我可以从URL中删除index.php。 ht访问规则如下

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /siebeluigen/

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

但是,如果我将控制器直接移动到控制器内的子文件夹中,则此操作将无效。 例如

如果我将我的应用程序控制器放在以下路径中

application/controllers/application.php

然后我可以从URL访问它

http://localhost/siebeluigen/application

但是如果我的目录结构是

application/controllers/app/application.php

然后我收到以下网址错误

http://localhost/siebeluigen/app/application

但是它是这样的

http://localhost/siebeluigen/index.php/app/application

因此,我非常确定htaccess中应该可以进行一些更改以使其正常运行。

请帮忙!!!

更新

我的htaccess文件位于应用程序文件夹中,而不是root。 将文件移动到index.php所在的文件夹即可解决此问题。 我已将答案标记为有效。 谢谢...

这是我在所有项目中使用的htaccess文件:

Options -Indexes
Options +FollowSymLinks

# Set the default file for indexes
DirectoryIndex index.php

<IfModule mod_rewrite.c>

    # activate URL rewriting
    RewriteEngine on

    # do not rewrite links to the documentation, assets and public files
    RewriteCond $1 !^(images|assets|uploads|captcha)

    # do not rewrite for php files in the document root, robots.txt or the maintenance page
    RewriteCond $1 !^([^\..]+\.php|robots\.txt)

    # but rewrite everything else
    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.

    ErrorDocument 404 index.php

</IfModule>  

然后-同时确保在您的config.php文件中

  $config['index_page'] = '';

编辑:您永远不要将某人指向您的应用程序文件夹-您始终将他们指向您的index.php-一切都通过Index.php-并且它将重新路由到需要的位置。

这通常是重定向到application.php的条件

RewriteCond %{REQUEST_URI} ^application.* 

应用程序/应用程序不符合此条件。 尝试将其更改为:

RewriteCond %{REQUEST_URI} ^app/application.* 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM