【问题标题】:CodeIgniter: Unable to remove index.php from URLCodeIgniter:无法从 URL 中删除 index.php
【发布时间】:2011-11-25 21:18:41
【问题描述】:

没有运气从 url 中删除 index.php 文件。

例如我想通过http://domain.com/welcome访问“欢迎”控制器

目前在尝试时也遇到 404 错误。

不过,目前我只能通过http://domain.com/index.php/welcome访问

我目前在从 CI 用户指南获得的 .htaccess 文件中有这个:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

我的 .htaccess 文件位于应用程序文件夹上方的目录中。

任何帮助都会很棒。

【问题讨论】:

    标签: codeigniter url


    【解决方案1】:

    我有以下 .htaccess

    <IfModule mod_rewrite.c>
        AcceptPathInfo On
    
        RewriteEngine On
    
        ### Canonicalize codeigniter URLs
    
        # If your default controller is something other than
        # "welcome" you should probably change this
        # RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
        # RewriteRule ^(.*)/index/?$ $1 [L,R=301]
    
        # Removes trailing slashes (prevents SEO duplicate content issues)
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.+)/$ $1 [L,R=301]
    
        # 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]
    
        # 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>
    
        # Without mod_rewrite, route 404's to the front controller
        ErrorDocument 404 /index.php
    
    </IfModule>
    

    另外,请确保您的 httpd.conf 的 AllowOverride 指令未设置为 None,因为这会阻止您的 .htaccess 规则被读取。

    【讨论】:

    猜你喜欢
    • 2013-08-09
    • 2012-12-27
    • 1970-01-01
    • 2023-03-25
    • 2015-05-26
    • 1970-01-01
    • 2012-11-14
    • 2016-05-14
    • 2014-10-28
    相关资源
    最近更新 更多