【问题标题】:how to use .htaccess for URL rewriting如何使用 .htaccess 进行 URL 重写
【发布时间】:2018-06-26 00:19:11
【问题描述】:

我的服务器上的 blog/ 文件夹中安装了一个 wordpress 网站。并且可以通过 domain.com/blog 访问它

但我需要从 domain.com/ 访问它,同时保持此文件夹中的现有应用程序按原样运行。在 root 上,我安装了 cakephp 2。 Cakephp 用于运行具有如下子域的应用程序:

  • abc.domain.com
  • xyz.domain.com

我希望它们在 root 上运行 wordpress 网站。

.htaccess 文件中的条目是什么?

【问题讨论】:

    标签: wordpress .htaccess cakephp-2.0


    【解决方案1】:

    在 .htaccess 中管理起来有点困难,但您可以在 WordPress 编码中完成。
    分两步完成

    第 1 步:在您的根目录上创建 index.php 并包含以下内容

    <?php
    /**
     * Front to the WordPress application. This file doesn't do anything, but loads
     * wp-blog-header.php which does and tells WordPress to load the theme.
     *
     * @package WordPress
     */
    
    /**
     * Tells WordPress to load the WordPress theme and output it.
     *
     * @var bool
     */
    define('WP_USE_THEMES', true);
    
    /** Loads the WordPress Environment and Template */
    require( dirname( __FILE__ ) . '/blog/wp-blog-header.php' ); /** here blog is place as your folder name */
    

    第 2 步:现在将数据库中的“domain.com”更改为“domain.com/blog”(对于此下载 sql > 打开并编辑以进行替换 > 上传新 sql)。

    现在您的完整站点在 domain.com URL 上运行,但文件从“博客”文件夹中调用。

    【讨论】:

    • 我已经有了 cakephp 的 index.php,这会影响我 cakephp 的代码吗?
    • 是的,它受到了影响。正如您所提到的,“但我需要从 domain.com/ 访问它”。因此,在单个域 url (domain.com) 上,您不能运行两个 webapp。
    猜你喜欢
    • 1970-01-01
    • 2016-09-10
    • 1970-01-01
    • 2020-04-09
    • 2011-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多