Codeigniter web.config或.htaccess index.php在子目录中重写

时间:2016-10-12 16:04:14

标签: apache codeigniter mod-rewrite iis web-config

我的网站文件夹结构如下......

Application Root
|- administration
|--|- application
|--|- system
|--|- index.php
|--|- web.config
|
|- application
|- system
|- index.php
|- web.config

此处安装了两个CI框架。

  1. site root
  2. 管理文件夹
  3. 这里我说的是administration子文件夹。

    我的web.config URL Rewrite如下所示。

    <rules>
             <rule name="Rewrite to index.php">
                <match url="index.php|robots.txt|images|test.php" />
                <action type="None" />
            </rule>
            <rule name="Rewrite CI Index">
                <match url=".*" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html" negate="true" />
                </conditions>
                <action type="Rewrite" url="index.php/{R:0}" />
            </rule>
        </rules>
    

    问题是,如果我从index.php $config['index_page']移除site_root/administration/application/config/config.php,则任何控制器功能都会显示 404页面未找到。网站根目录web.config实际上正在执行此操作。

    我想从子目录中的URL中删除index.php

    1。我怎么能通过web.config执行它?

    2。我怎么能通过.htaccess执行它?

    我找到了 THIS ,但没有得到答案。

6 个答案:

答案 0 :(得分:1)

我只是根据Linux系统上的文件夹结构运行一个模型。

我在codeigniter用户指南中找到了标准的htaccess文件。所以有两个.htaccess文件。一个在主应用程序(root)文件夹中,另一个在管理文件夹下。

在两个配置文件中从$ config ['index_file'] =''中删除了index.php。

使用whoami方法创建了一个家庭控制器,该方法只回显了“我是管理家庭控制器页面”,用于由/ administration / home / whoami调用的管理家庭控制器和“我是主要的家庭控制器” /家/ WHOAMI。

两者都返回了相应的消息,表明每个消息都被正确调用。

.htaccess直接退出用户指南。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

所以我想这同样适用于IIS,但不要指责我。 我找到了一些可能有帮助的东西...... web.config version of the .htaccess

因此,对于上述设置,您应该能够输入相应的网址以同时访问两个CI实例。

答案 1 :(得分:1)

您会尝试在administration部分之前添加CI Index规则,如下所示:

    <rule name="Rewrite Administration Index">
        <match url="administration/(.*)" />
        <conditions>
            <add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html" negate="true" />
        </conditions>
        <action type="Rewrite" url="administration/index.php/{R:1}" />
    </rule>
    <rule name="Rewrite CI Index">
        <match url=".*" />
        <conditions>
            <add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html" negate="true" />
        </conditions>
        <action type="Rewrite" url="index.php/{R:0}" />
    </rule>

答案 2 :(得分:1)

我遇到了同样的问题,但它现在正在工作。这对我有用。傅旭的答案很好,但并没有起到相应的作用。所以,如果你对他的代码进行了以下修改,它可能对你有用。就像它对我一样 我改变了 <rule name="Rewrite Administration Index">

<rule name="Rewrite Administration Index" stopProcessing="true">

然后我改变了 <match url="administration/(.*)" />

<match url="^administrator/(.*)$" ignoreCase="true"/>

然后
<conditions>

<conditions logicalGrouping="MatchAll">

并修改了这个 <add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html" negate="true" />

<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />

这里是完整的代码:

<rule name="Rewrite Administration Index" stopProcessing="true">
  <match url="^administration/(.*)$" ignoreCase="true"/>
  <conditions logicalGrouping="MatchAll">
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  </conditions>
  <action type="Rewrite" url="administration/index.php/{R:1}" />
</rule>

<rule name="Rewrite CI Index" stopProcessing="true">
  <match url="^(.*)$" ignoreCase="true" />
  <conditions logicalGrouping="MatchAll">
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  </conditions>

  <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
</rule>

我希望这对你有用

答案 3 :(得分:0)

在htaccess文件中编辑...将从您的网址中删除index.php。

#include <stdio.h>

int main() {
    int numbers[3];
    printf("Enter number 1: \n");
    scanf("%d", &numbers[0]);

    printf("Enter number 2; \n");
    scanf("%d", &numbers[1]);

    printf("Enter number 3: \n");
    scanf("%d", &numbers[2]);

    printf("%d %d %d\n", numbers[0], numbers[1], numbers[2]);

    int maximum_0 = 0;
    int maximum_1 = 0;

    int i;


    for (i = 0; i < 3; i++) {
        if (numbers[i] > maximum_0) {
            maximum_0 = numbers[i];
        }
    }

    for (i = 0; i < 3; i++) {
        if (numbers[i] > maximum_1 && numbers[i] < maximum_0) {
            maximum_1 = numbers[i];
        }
    }

    printf("Result: %d\n", (maximum_0 - maximum_1)); 

    return 0;
}

答案 4 :(得分:0)

1)在应用程序根目录中创建文件名= .htaccess。在.htaccess文件中添加以下代码。

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

2)转到application-&gt; config-&gt; config.php。

replace $config['uri_protocol'] = 'REQUEST_URI';

这一个

$config['uri_protocol'] = 'AUTO';

答案 5 :(得分:0)

    1.Go to **"application/config/config.php"** then Edit
     $config['index_page'] = "index.php" 
     To 
     $config['index_page'] = ""
     AND
     $config['uri_protocol'] ="AUTO"
     to
     $config['uri_protocol'] = "REQUEST_URI"

    2.Now go to Root directory not Inside */application* then create file with file name .htaccess and paste the bellow code and save the file.

    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

    3.Now you have to enable your server rewrite_mode/rewrite_module, so search for it in google For your LAMP/WAMP server...

    4.restart your server

You nailed it bro, Now everything is done...
相关问题