CodeIgniter:无法从URL中删除index.php [英] CodeIgniter: Unable to remove index.php from URL

查看:61
本文介绍了CodeIgniter:无法从URL中删除index.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Having no luck removing the index.php file from the url.

例如,我想通过 http://domain.com/welcome

当前在尝试时出现404错误

Currently getting a 404 error when attempting too.

但是,目前我只能通过 http://domain.com/index.php/welcome

However, at the moment I can only access is via http://domain.com/index.php/welcome

我目前在.htaccess文件中有此文件,该文件是从CI用户指南:

I have this currently in my .htaccess file which I got from the CI user guide:

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

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

I have the .htaccess file located in the directory above the application folder.

任何帮助都会很棒。

推荐答案

我有以下.htaccess

I have the following .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规则。

Also, please be sure that the AllowOverride directive of your httpd.conf is not set to None, since that would prevent your .htaccess rules to be readed.

这篇关于CodeIgniter:无法从URL中删除index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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