【问题标题】:Installing CodeIgniter on root and WordPress in sub-directory在根目录和 WordPress 子目录中安装 CodeIgniter
【发布时间】:2011-01-31 09:55:39
【问题描述】:

我想创建一个网站,主要页面将由 CodeIgniter 提供。我将使用 /blog/ 子目录中的 Wordpress 来托管博客。而已!我什么都不想要。只是为了确保:

example.com/somepage/ 调用 CI 控制器,其中 example.com/blog/some-post/ 由 Wordpress 处理。

我不需要 CI 和 WP 之间的任何类型的集成或交互。

可以这样安装吗?如果没有,有什么解决方法可以实现目标?

感谢和问候, 玛斯农

【问题讨论】:

    标签: php wordpress codeigniter


    【解决方案1】:

    用 Rich 的方法+1

    另外,如果您使用 .htaccess 文件,如 CI doc 中建议的文件,它应该通过将 WP 目录直接放入 Web 根目录来工作。

    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]
    
    #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
    #This last condition enables access to the images and css folders, and the robots.txt file
    #Submitted by Michael Radlmaier (mradlmaier)
    
    
    RewriteCond $1 !^(index\.php|robots\.txt|corporate|assets)
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    由于RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d 直接对网络服务器上的真实文件进行的任何调用都将由Apache 直接提供服务,其他uri 将由CI 的路由机制处理。

    请注意,我们使用了最后一个 RewriteCond 指令来排除对某些文件的调用,包括我们的资产目录(包含图像/css/js 静态文件)和在本例中包含博客的“公司”目录。

    虽然这个例子没有使用 wordpress,但它有自己的 url 重写和路由系统。

    总而言之,如果您想使用 WP url-rewriting,您将使用特定的 RewriteCond 语句,否则它可以在没有它的情况下工作。

    【讨论】:

    • 这个答案对我来说非常准确,因为上面标记为正确的答案弄乱了我的资产文件
    【解决方案2】:

    我怀疑您可以使用站点根目录中的 .htaccess 文件来实现此功能。如果 blog 是安装 WordPress 的子目录的名称,并且您希望 example.com/blog 由 WordPress 处理,试试这个看看是否有帮助:

    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|robots\.txt|blog)
    RewriteRule ^(.*)$ /index.php/$1 [L]
    

    【讨论】:

    • 谢谢。从它的外观来看,它应该可以工作。我要试试这个。
    • 这就是我们将 CI 与其他应用程序/站点集成的方式。这可能会被拒绝以两种方式工作:CI 应用程序进入 wordpress 目录,以及 wordpress 在 CI 应用程序目录中。
    • @Rich Miller 它对我不起作用。你能检查问题stackoverflow.com/questions/32534801/…
    【解决方案3】:

    它应该像您描述的那样工作,无需任何复杂的配置。只需在您的根目录中安装 codeigniter,然后创建一个博客目录并将 wordpress 放在那里。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-08
      • 2014-11-24
      • 2018-02-05
      • 2014-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多