【问题标题】:Codeigniter mod_rewrite for both root and subdirectory根目录和子目录的 Codeigniter mod_rewrite
【发布时间】:2013-06-06 13:39:10
【问题描述】:

我有:

root/.htaccess

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php/$1 [QSA,L]

它可以完美地将所有请求(文件和文件夹除外)发送到 index.php。我也需要它在我的子文件夹中工作。
我在子文件夹root/demos/project 中有.htaccess 包含:

RewriteOptions inherit

但不起作用。

我在 root/.htaccess 中试试这个

RewriteRule ^(.*)$ index.php/$1 [QSA,L]
RewriteRule ^demos/project/(.*)$ demos/project/index.php/$1 [QSA,L]

没用。

这个:

RewriteRule ^demos/project/(.*)$ demos/project/index.php/$1 [QSA,L]
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

获取内部服务器错误'missconfiguration'

还有很多方法,但我尝试过的所有方法都得到了这些:501(默认来自服务器)和 404(来自 root 中的 ci);

我在root 和demos/project 中都使用了codeigniter,只想从两者中“隐藏”index.php,如何正确执行此操作?

谢谢。

【问题讨论】:

    标签: codeigniter .htaccess mod-rewrite


    【解决方案1】:
    RewriteEngine on
    RewriteRule ^(.*)$ /demo/project/index.php?/$1 [L]
    

    这行得通吗?

    您也可以在演示/项目文件夹中放置另一个 .htaccess。

    编辑:

    试试这个:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /demo/project/index.php?/$1 [L]
    

    EDIT2:

    如果你得到一个 404 not found 页面,只需从以下更改 root/application/config/config.php 中的 config.php:

    $config['index_page'] = "index.php";
    

    到:

    $config['index_page'] = "";
    

    【讨论】:

    • 内部服务器错误missconfiguration。 :(
    • 还是一样:500 internal server error。我也使用类似的 sintax 将 .htaccess 添加到我的子文件夹中,我尝试过的所有内容,我只得到这些:500 或 404。
    • 当你得到 404 它应该工作。您是否删除了配置文件中的索引页?根/应用程序/config/config.php:$config['index_page'] = "";
    • 但是你得到了 404 页面吗?那么我的第二次编辑应该可以工作。如果您收到 500 错误,它无论如何都不起作用。
    猜你喜欢
    • 2011-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-19
    • 1970-01-01
    • 2011-07-04
    • 1970-01-01
    相关资源
    最近更新 更多