【问题标题】:Multiple Mod_ReWrites on one site - Possible? (Wordpress blog in root directory, CodeIgniter project in subdirectory)一个站点上的多个 Mod_ReWrites - 可能吗? (Wordpress 博客在根目录,CodeIgniter 项目在子目录)
【发布时间】:2011-02-02 18:30:02
【问题描述】:

目前我正在使用 CodeIgniter 创建一个项目,该项目包含在我的域的子目录中。对于此示例,我们将其命名为 domain.com/test。

我还在这个域上安装了 Wordpress,它的所有文件都在根目录下。例如,如果您导航到 my domain.com,那么它会打开 Wordpress 博客。我目前激活了 Wordpress mod_rewrite,以便它使用友好的 URL。

对于那些不熟悉 CodeIgniter 的人,所有请求都通过项目根文件夹中的 index.php 进行路由。因此,在这种情况下,它将是 domain.com/text/index.php。对应用程序的请求将像 domain.com/test/index.php/somecontroller/method 一样发送。

我想做的是针对任何指向 /test/ 文件夹或其中的某些子目录的传入请求,我希望它适当地重写 URL,以便不包括 index.php。 (根据上面的示例,它最终会成为 domain.com/test/somecontroller/method)

对于任何 OTHER 请求,即不在 /test/ 目录中的任何请求,我希望它将请求路由到 Wordpress。

我想这是一个简单的 RewriteCond 来检查请求是针对 /test/ 目录还是其中的子目录,但我不知道该怎么做。也许每个站点最多只能有一组重写规则。

我将为每个应用程序包含推荐的 mod_rewrite 规则。

Wordpress:(目前使用)

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

CodeIgniter:(取自他们的Wiki

<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 添加到 /test/ 子目录中,其中包含的规则显然会覆盖父目录规则。但是,我仍然想知道这是否可以在一个 .htaccess 中实现。
  • 您需要单独的 .htaccess 文件,因为如果用户进入测试目录,根目录中的 .htaccess 将不会被看到,因此其指令被忽略...

标签: apache wordpress .htaccess mod-rewrite codeigniter


【解决方案1】:

@Myself 和 Stormdrain - 正如我在上面的评论中所述(并由 Stormdrain 阐述),只需将 CodeIgniter .htaccess 放在 /test/ 子目录中就可以了。

啊,我还应该注意,我确实必须从以下代码修改 CodeIgniter .htaccess BasePath 行: 重写基础/

对此: RewriteBase /test/

希望这可以帮助其他有相同/类似问题的人。

-Sootah

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-11
    • 1970-01-01
    • 2023-04-09
    • 2011-01-31
    • 1970-01-01
    • 2015-09-28
    • 1970-01-01
    相关资源
    最近更新 更多