0
RewriteEngine On
RewriteBase /path/learn_ci

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /path/learn_ci/$1 [L]

上面我的 .htaccess 文件是如何配置的。

4

3 回答 3

1

在您的 .htaccess 文件中放入以下代码。

RewriteEngine On
RewriteBase /path/learn_ci
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|css|asset|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

在你的application/config/config.php上放下面的代码

$config['base_url'] = 'http://yourdomain.com/';
$config['index_page'] = '';

它会为你工作。

享受...!!!:)

于 2013-05-14T06:41:21.383 回答
0

这是我在大多数 CodeIgniter 项目中一直使用的,从未遇到过问题。

你需要调整你的 RewriteBase。它从 Web 服务器的根目录开始 /www/your_project 将在 htaccess 文件中更改为 /your_project/。

另外,请确保您启用了 mod_rewrite。

如何为 Apache 2.2 启用 mod_rewrite

CodeIgniter htaccess 和 URL 重写问题

此外,您需要从 CodeIgniter 安装中的 config.php 中的 $config['index_page'] = 'index.php' 中删除 index.php。

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

    #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 $1 !^(index\.php|img|font|css|temp|js|robots\.txt|favicon\.ico)
    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>
于 2013-05-14T06:42:25.767 回答
0

这应该是项目根文件夹中的 htaccess 文件

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase / yourproject


#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.php 中删除 index.php,如下所示:$config['index_page'] = '';

于 2013-05-14T06:43:07.287 回答