2

我想在子目录中安装最新版本的 codeigniter。到目前为止有效。但现在我想index.php从网址中删除。因此,我.htaccess在子文件夹中有这个文件。

RewriteEngine On
RewriteBase /dev/

# 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.*
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]

子文件夹的名称为dev,webroot(父文件夹)为空。里面只有一个index.html文件。

所以这导致了这个结构:

/var/www/
    index.html
    dev/
        ci installation here
        .htaccess

当然mod-rewrite是启用的。

任何想法为什么它不起作用?调用http://domain.tld/dev/login 之类的内容时出现 404 错误

4

2 回答 2

4

你需要两件事。

config.php, 配置index_page为空,因此正确创建了 URL

$config['index_page'] = '';

在你的.htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php/$0

Codeigniter 提供的这些子目录中的文件已经禁止访问system和目录。application.htaccess

于 2013-04-05T22:55:40.113 回答
1

试试下面的代码。

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
于 2013-04-05T21:55:32.800 回答