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

WordPress站点.htaccess配置:主页映射至main子目录,其余页面保留根目录

Solution for Serving New Homepage from Subdirectory While Keeping Other Pages on Root WordPress

Got it, let's work through this .htaccess setup to get exactly what you need: serving your new /main WordPress homepage at example.com (no URL redirect) while keeping all other pages like example.com/about-us pointing to your root WordPress site.

Step 1: Update Root .htaccess

First, replace or modify your root directory's .htaccess file with these rules. This will prioritize the new homepage forward while letting all other requests fall back to your existing root site:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# Serve the new homepage from /main (internal rewrite, no URL change)
RewriteRule ^$ /main/ [L]

# Default WordPress rules for all other requests (uses root site)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Step 2: Fix WordPress Configuration in /main

To make sure your new /main WordPress site loads resources (CSS, JS, images) correctly without pointing to /main in URLs, add these lines to your /main/wp-config.php file (right before the line that says /* That's all, stop editing! Happy publishing. */):

define('WP_HOME','https://example.com');
define('WP_SITEURL','https://example.com/main');

This tells the /main WordPress installation that its public-facing URL is the root domain, even though its core files live in the subdirectory.

Step 3: Test and Verify

  • Visit example.com: You should see your new /main homepage, with the URL still showing example.com (no redirect to /main).
  • Visit example.com/about-us (or any other existing page): You should land on your original root WordPress site's page.
  • Check the new homepage's source code to ensure all asset links (CSS, JS) point to https://example.com/wp-content/... instead of including /main (the wp-config.php changes take care of this).

Key Notes

  • Make sure your server has mod_rewrite enabled (most Apache hosts have this on by default, but if not, you may need to contact your host or enable it via cPanel).
  • If you have existing custom rules in your root .htaccess, merge these carefully—keep the homepage rewrite rule above the default WordPress index.php rule.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 11:08:51