【问题标题】:Run wordpress on a separate directory在单独的目录上运行 wordpress
【发布时间】:2014-07-29 16:26:37
【问题描述】:

我想通过子目录运行 wordpress 站点,但保留实际域。

这就是我想要做的。

假设我有一个网站 www.xyz.com

我在根目录上安装了一个 wordpress 实例。但是,我想在子目录中安装一个新的 wordpress 实例。我想将根 worpdress 实例指向子目录并保留域名而不引用子目录。

子目录可以称为“test”。在 test 目录下,我会安装一个新的 wordpress 实例。

现在,我想将 www.xyz.com 指向“test”目录,并且链接仍然是 www.xyz.com。所有链接都应该是 www.xyz.com/post-name-sample 而不是 www.xyz.com/test/post-name-sample。

我需要在 .htaccess 文件中设置一个 mod-rewrite 规则吗?

感谢您的帮助。谢谢!

【问题讨论】:

    标签: php wordpress apache .htaccess mod-rewrite


    【解决方案1】:

    尝试将其添加到 .htaccess 文件中

     .htaccess main domain to subfolder redirect
     # Copy and paste the following code into the .htaccess file
     # in the public_html folder of your hosting account
     # make the changes to the file according to the instructions.
    
     # Do not change this line.
     RewriteEngine on
    
     # Change yourdomain.co.uk to be your main domain.
     RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.co.uk$
    
     # Change ‘subfolder’ to be the folder you will use for your main domain.
     RewriteCond %{REQUEST_URI} !^/subfolder/
    
     # Don’t change this line.
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d
    
     # Change ‘subfolder’ to be the folder you will use for your main domain.
     RewriteRule ^(.*)$ /subfolder/$1
    
     # Change yourdomain.co.uk to be your main domain again.
     # Change ‘subfolder’ to be the folder you will use for your main domain
     # followed by / then the main file for your site, index.php, index.html, etc.
    
     RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.co.uk$
     RewriteRule ^(/)?$ subfolder/index.php [L]
    

    【讨论】:

    • 如果在使用 wordpress 默认永久链接时效果很好。我在使用 post-name 永久链接时遇到服务器 500 错误。请帮忙谢谢
    【解决方案2】:

    可以在 wordpress 上使用:here 是如果您已经将它安装在子目录中的方法。

    1. 转到常规面板。
    2. 在站点地址 (URL) 框中:更改 根目录的 URL 地址。示例:http://example.com
    3. 单击保存更改。 (不要担心错误信息,不要 此时尝试查看您的博客!您可能会收到一条消息 关于找不到文件。)
    4. 复制(不要移动!)index.php 和 .htaccess 将 WordPress(在我们的示例中为 wordpress)目录中的文件放入 您网站的根目录——后者可能被命名为 像 www 或 public_html 之类的东西。 .htaccess 文件是不可见的, 因此您可能需要将 FTP 客户端设置为显示隐藏文件。如果你 没有使用漂亮的永久链接,那么你可能没有 .htaccess 文件。如果您在 Windows (IIS) 服务器上运行 WordPress 并且 使用漂亮的永久链接,您将拥有一个 web.config 而不是 .htaccess 文件在您的 WordPress 目录中。
    5. 编辑根目录的 index.php。
      1. 打开根目录的 index.php 文件 文本编辑器
      2. 使用您的目录将表示:require( dirname( __FILE__ ) . '/wp-blog-header.php' ); 的行更改为以下内容 WordPress 核心文件的名称:require( dirname( __FILE__ ) . '/wordpress/wp-blog-header.php' );
      3. 保存文件。
    6. 登录到您的站点 (如果你还没有)。 URL 应该仍然是 http://example.com/wordpress/wp-admin/
    7. 如果您已设置 永久链接,转到永久链接面板并更新您的永久链接 结构体。 WordPress 将自动更新您的 .htaccess 文件 如果它具有适当的文件权限。如果 WordPress 不能写 到您的 .htaccess 文件,它将显示新的重写规则 您,您应该手动将其复制到您的 .htaccess 文件中(在 与主 index.php 文件相同的目录。)

    【讨论】:

      猜你喜欢
      • 2023-04-09
      • 2021-01-16
      • 1970-01-01
      • 2012-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-07
      • 1970-01-01
      相关资源
      最近更新 更多