【问题标题】:htaccess help in coexisting Codeigniter and Wordpress installhtaccess 帮助共存的 Codeigniter 和 Wordpress 安装
【发布时间】:2012-01-06 00:30:49
【问题描述】:

我的目的是在同一域下创建一个带有博客的 codeigniter 应用程序。两者的管理员应该是分开的。

目录结构是这样的:

httpdocs/.htaccess
httpdocs/application/ <== CI installation
httpdocs/blog/        <== WP installation
httpdocs/blog/.htaccess

网址应该是这样的:

mysite.com         <== CI
mysite.com/tools   <== CI
mysite.com/forum   <== CI
mysite.com/blog    <== WP

我按照this tutorial 进行设置,效果很好。

我的 codeigniter 应用程序和 WP博客主页 完全按照应有的方式显示,并带有正确的 URL、样式等。

我也可以正常访问 mysite.com/blog/wp-admin 以获取 WP 后端内容。

我的问题是当我尝试访问实际的博客文章时,例如:

mysite.com/blog/fiction/what-is-going-on/

当我这样做时,我得到 Codeigniter 的 404 错误页面

我的根 .htaccess (httpdocs/.htaccess) 是这样的:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

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

我的博客 .htaccess (httpdocs/blog/.htaccess) 是这样的:

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

知道我做错了什么吗?如果需要,将发布更多信息。提前致谢。

【问题讨论】:

    标签: php wordpress .htaccess codeigniter mod-rewrite


    【解决方案1】:

    好的解决方案是使用

    CI .htaccess

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    

    WP .htaccess

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

    成功了。现在所有页面都显示没有问题。

    【讨论】:

      【解决方案2】:

      我一般在CI.htaccess上使用2组条件(一组在根文件夹)

      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^blog/(.*)$ blog/index.php [L]
      
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php/$1 [L]
      

      这将允许首先处理博客 URL,然后再处理 CI URL。您需要注意不要在您的应用程序中使用术语 blog 的任何控制器或路由。

      【讨论】:

      • thx @dakdad 但它不起作用 - 我仍然得到 CI 的 404 博客文章页面 - 关于如何解决这个问题的任何其他想法?
      • @dakdad 在我们为用户运行博客时,如果您需要在控制器中使用“博客”怎么办?
      • @Stefan 相同的 uri 不能提供两件事,其中一件需要不同。
      • @sakdad 这难道不是 Htaccess 重写规则并检测主机是博客而不是子域或自定义域上的用户博客吗?
      【解决方案3】:

      我会在你的 Wordpress .htaccess 中尝试三件事(不要碰 CI ——它看起来是正确的):

      首先,尝试删除 index.php 之前的正斜杠:

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

      如果这不起作用,那么请尝试将 RewriteBase 设置为 /blog/:

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

      最后,如果这些都不起作用,您可以尝试在最后的 index.php 行中手动添加“/blog/”:

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

      【讨论】:

      • 有什么理由使用您的代码而不是我上面的答案?我的似乎工作正常,但我想知道您是否对我如何将它组合在一起有任何意见,以及您的解决方案是否有任何优势
      猜你喜欢
      • 2015-10-23
      • 2020-12-08
      • 2010-12-15
      • 2011-07-28
      • 2011-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多