【问题标题】:htaccess and mod_rewrite codeigniterhtaccess 和 mod_rewrite 代码点火器
【发布时间】:2011-07-19 19:44:32
【问题描述】:

我正在使用 codeigniter,下面是我的 htaccess 文件。但是,我希望可以通过我的 domain.com/directory 在 codeigniter 应用程序之外访问单个目录。另一个目录是与codeigniter无关的论坛。我将如何在 htaccess 中设置规则?我无权访问 http.conf

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #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>

【问题讨论】:

    标签: .htaccess mod-rewrite codeigniter


    【解决方案1】:

    这应该已经可以了。 RewriteCond %{REQUEST_FILENAME} !-d 告诉 mod_rewrite 忽略实际目录,RewriteCond %{REQUEST_FILENAME} !-f 告诉它忽略实际文件。

    【讨论】:

    • 我正在尝试一些东西,但我认为的问题是,当我导航到 domain.com/directory 时,codeigniter 将目录视为控制器,但我希望将该目录视为普通文件夹。它有自己的 index.php 和 htaccess 文件。让我看看这个测试是如何进行的。但是你明白我在说什么吗?我应该还好吗?
    • 我的意思是我不知道为什么这是个问题。 RewriteCond %{REQUEST_FILENAME} !-d 表示如果文件名实际上是文件夹,则不重写。要尝试的一件事是在 URL 的末尾添加一个斜杠:domain.com/directory/ 而不是 domain.com/directory
    【解决方案2】:

    我使用它来排除任何文件夹作为控制器被解析为 codeigniter 框架。 所以 www.domain.com/images/ 会像普通文件夹一样运行,等等。在那里你可以放置你自己的 htaccess 指令。祝你好运!

    RewriteCond $1 !^(folders_to_exclude_from_CI|images|css|assets|resources|robots\.txt)
    

    【讨论】:

      猜你喜欢
      • 2011-07-28
      • 1970-01-01
      • 1970-01-01
      • 2016-10-20
      • 2015-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多