Codeigniter web.config或.htaccess index.php在子目录中重写 [英] Codeigniter web.config or .htaccess index.php rewrite inside a subdirectory

查看:178
本文介绍了Codeigniter web.config或.htaccess index.php在子目录中重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

my website folder structure is like below...

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

这里安装了两个 CI 框架。


  1. site root

  2. 管理文件夹

这里我说的是管理子文件夹。

Here I am talking about the administration subfolder.

我的web.config 网址重写如下所示。

My web.config URL Rewrite is like below.

<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 实际上是这样做的。

problem is, if I remove index.php from $config['index_page'] of site_root/administration/application/config/config.php, any controller function shows 404 page not found. The site root web.config actually doing this.

我想删除索引。 php 来自子目录中的URL。

I want to remove index.php from URL inside the subdirectory.

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

1. How could I perform it through web.config ?

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

2. How could I perform it through .htaccess ?

我发现 THIS ,但没有得到答案。

I found THIS, but got no answer.

推荐答案

我遇到了同样的问题,但它现在正在运作。这对我有用。傅旭的答案很好,但效果不太好。因此,如果您对他的代码进行了以下修改,它可能对您有用。就像它对我一样。

我改变了

< rule name = 重写管理索引>



<规则名称=重写管理索引stopProcessing =true >

I had the same problem but it's working now. Here's what worked for me. Fu Xu's answer was good, but it didn't quite work. So, if you make the following modifications to his code, it may work for you as it did for me.
I changed
<rule name="Rewrite Administration Index">
to
<rule name="Rewrite Administration Index" stopProcessing="true">

然后我更改了
< match url =administration /(。 *)/>

to

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

然后

< conditions>

to

< conditions logicalGrouping =MatchAll>

并且还修改了这个

< add input ={REQUEST_FILENAME}pattern =css | js | jpg | jpeg | png | gif | ico | htm | htmlnegate =true/>

to

< add input ={REQUEST_FILENAME} matchType =IsDirectorynegate =true/>
< add input ={REQUEST_FILENAME}matchType =IsFilenegate =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>

我希望这对你有用

这篇关于Codeigniter web.config或.htaccess index.php在子目录中重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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