【问题标题】:HTaccess not rerouting [CodeIgniter]HTaccess 未重新路由 [CodeIgniter]
【发布时间】:2011-12-04 16:50:00
【问题描述】:

我有一个应用程序在使用完整 url 时效果很好:sitename.com/index.php/foo/ 但是当我使用 HTaccess 删除 index.php 时,它似乎没有按预期工作。无论我访问哪个页面,我都只能看到主页。 htaccess 文件正在执行某些操作,因为没有该行,我会收到 404 错误。

    RewriteEngine on
    RewriteCond $1 !^(index\.php|assets|file-manager-files|robots\.txt|favicon\.ico)
    RewriteRule ^(.*)$ /index.php/$1 [L]

想法?

在我的测试站点上一切正常。这是需要调整的服务器设置吗?

【问题讨论】:

    标签: .htaccess codeigniter


    【解决方案1】:

    使用 Codeigniter 你想要这样的东西:

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

    如果这不起作用,请检查以确保 $config['index_page'] = ''; 和您的 .htaccess 指令设置正确:

    <Directory "/some/absolute/path/htdocs">
    Options Indexes Includes FollowSymLinks MultiViews
    AllowOverride AuthConfig FileInfo
    Order allow,deny
    Allow from all
    </Directory>  
    

    我已经在许多操作系统配置上完成了数百次 Codeigniter 安装,并且始终能够使其正常工作,但我偶尔会遇到一些问题,我必须发挥创造力才能让 index.php 消失。

    【讨论】:

    • 感谢您的解决方案!我对 mod rewrite 仍然很天真,但这让一切正常。我仍然不明白为什么我以前的 htaccess 文件在一台服务器上运行而不是在下一台服务器上运行,但我很高兴这个解决方案确实有效。
    【解决方案2】:

    RewriteCond 错误。在第一个参数中,您必须使用要检查的内容。例如请求的 URI、脚本文件名等。在上面的示例中,您似乎尝试将 $1(dolar 和 one)与 Rewrite Condition 的右侧部分进行比较:?

    【讨论】:

    猜你喜欢
    • 2017-12-04
    • 2011-06-18
    • 2016-11-05
    • 1970-01-01
    • 2019-07-30
    • 2013-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多