You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将WordPress置于子目录且保留permalinks,静态HTML作首页

Got it, let's tackle this step by step—since the standard Codex method isn't working for your specific setup, we'll use a custom approach that keeps your static Bootstrap homepage at the root, lets WordPress live in /subdirectory, and preserves your original root-level permalinks for all WP pages (except the WP homepage, which stays locked to /subdirectory).

Step 1: Move WordPress to the Subdirectory

First, get your WordPress files into the /subdirectory folder on your server:

  • Using FTP or your host's file manager, create a new folder named subdirectory in your site's root directory.
  • Move all your WordPress core files, themes, plugins, and the wp-content folder into this subdirectory folder.

Step 2: Update WordPress Settings

Log into your WordPress dashboard (you'll need to access it temporarily at www.exampledomain.com/subdirectory/wp-admin) and adjust these critical settings:

  • Go to Settings > General
    • Set WordPress Address (URL) to www.exampledomain.com/subdirectory (this tells WP where its core files live)
    • Leave Site Address (URL) as www.exampledomain.com (this keeps your permalinks rooted at the domain, not the subfolder)
  • Save your changes. You might get logged out—just log back in at the /subdirectory/wp-admin URL.

Step 3: Set Up Your Static Bootstrap Homepage

  • In your site's root directory, create (or replace) an index.html file with your Bootstrap static page content. This will be your default homepage.
  • Ensure your server prioritizes index.html over WordPress's index.php:
    • For Apache: Add this line to the top of your root .htaccess file:
      DirectoryIndex index.html index.php
      
    • For Nginx: Update your server block's index directive to:
      index index.html index.php;
      

Step 4: Configure .htaccess Rules (The Magic Part)

This is where we route traffic correctly so your static homepage loads at the root, WP's homepage stays at /subdirectory, and all other WP pages load with root-level permalinks.

Root Directory .htaccess

Replace or update your root .htaccess with this code:

# Prioritize static homepage
DirectoryIndex index.html index.php

RewriteEngine On
RewriteBase /

# Load static homepage for root request
RewriteRule ^$ index.html [L]

# Allow direct access to the WordPress subdirectory
RewriteRule ^subdirectory/ - [L]

# Route all other non-file/non-directory requests to WordPress in subdirectory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdirectory/index.php [L]

WordPress Subdirectory .htaccess

Go to the /subdirectory folder and make sure its .htaccess has this code (if it doesn't, update it):

RewriteEngine On
RewriteBase /subdirectory/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdirectory/index.php [L]
  • Test your setup:
    • www.exampledomain.com loads your Bootstrap static homepage
    • www.exampledomain.com/subdirectory loads your WordPress homepage
    • www.exampledomain.com/somepage loads your WordPress page without the /subdirectory prefix
  • If permalinks are broken, head to WP Admin > Settings > Permalinks and click "Save Changes" (no need to edit anything—this refreshes WP's permalink rules).

Pro Tip

Always back up your .htaccess files and WordPress database before making these changes, just in case you need to roll back.

内容的提问来源于stack exchange,提问作者Greg Viv

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 06:43:09