首页 > 解决方案 > 如何使用 .htaccess 切换内容以在维护消息下显示

问题描述

我想/blog在我的应用程序上有一个目录,以便在那里安装一个 WordPress 实例。目前/blog确实将我带到那里,但我确实想知道并拥有控制权,而不是如何从目录中读取routes.php.

它可能有很多用例,因为blog目录正在维护或关闭,在这种情况下,只需进行简单的更改,它就会/blogroutes.php.

我不是'.htaccess'文件的专家,但我们可以这样做吗?

标签: php.htaccesscodeignitercodeigniter-3

解决方案


如果您的 CI 应用程序使用默认路由配置,那么 /blog 将使 CI 尝试加载博客控制器和索引操作,如果它找不到它们。你会得到 404 page not found 错误。尝试在您的 Web 服务器配置中配置 /blog。添加 /blog 块,然后在那里应用 wordpress 服务器配置。确保请求将在 /location 块之前找到 /blog 位置块。在 nginx 中:

location /blog {
    # This is cool because no php is touched for static content.
    # include the "?$args" part so non-default permalinks doesn't break when using query string
    try_files $uri $uri/ /index.php?$args;
}

# then your ci / location
location / {
    # Check if a file or directory index file exists, else route it to index.php.
    try_files $uri $uri/ /index.php;
}

推荐阅读