一个站点上有多个 Mod_ReWrites - 可能吗? (Wordpress 博客位于根目录,CodeIgniter 项目位于子目录)

发布于 2024-08-26 20:09:14 字数 2368 浏览 3 评论 0原文

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

我还在这个域上安装了 Wordpress,它的所有文件都在根目录中。例如,如果您导航到我的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)

对于任何其他请求,即不在/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>

非常感谢任何和所有帮助!!

谢谢,

-苏塔

Currently I am creating a project with CodeIgniter that is contained within a subdirectory of my domain. For this example we'll call it domain.com/test.

I also have Wordpress installed on this domain, and all of its files are in the root. For instance, if you navigate to my domain.com then it pulls up the Wordpress blog. I currently have the Wordpress mod_rewrite activated so that it uses friendly-URLs.

For those of you that aren't familiar with CodeIgniter, all requests are routed through index.php in the project's root folder. So, in this case, it'd be domain.com/text/index.php. A request to the application would be sent like domain.com/test/index.php/somecontroller/method.

What I'd like to do, is for any incoming request that is directed towards the /test/ folder, or some subdirectory therein I'd like it to appropriately rewrite the URL so the index.php isn't included. (As per the example above, it'd end up being domain.com/test/somecontroller/method)

For any OTHER request, meaning anything that's not within the /test/ directory, I would like it to route the request to Wordpress.

I would imagine it's a simple RewriteCond to make it check to see if the request is for the /test/ directory or a subdirectory therein, but I've no idea how to do it. Perhaps you can't have more than one set of Rewrite Rules per site.

I will include the recommended mod_rewrite rules for each application.

Wordpress: (Currently used)

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

CodeIgniter: (Pulled from their 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>

Any and all help is much appreciated!!

Thanks,

-Sootah

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悲欢浪云 2024-09-02 20:09:14

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

啊,我还应该注意,我确实必须修改 CodeIgniter .htaccess BasePath 行:
RewriteBase /

到此:
RewriteBase /test/

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

-Sootah

@Myself and Stormdrain - As stated in my comment above (and expounded upon by Stormdrain), simply putting the CodeIgniter .htaccess in the /test/ subdirectory did the trick.

Ah, I should also note that I did have to modify the CodeIgniter .htaccess BasePath line from this:
RewriteBase /

to this:
RewriteBase /test/

Hopefully this helps anybody else that has the same/a similar question.

-Sootah

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文