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

如何缩短WordPress网站路径?将子目录部署的WordPress页面访问路径改为根目录形式

Fixing WordPress Page URL to Root Path (Removing Subdirectory)

Hey there! Let's get your about page's URL changed from http://localhost:82/_testwebsite/wordpress/about/ to http://localhost:82/about/—here's a step-by-step breakdown to make it happen:

Step 1: Update WordPress Site & Home URLs

First, we need to adjust the core WordPress settings to reflect your desired root URL:

  • Log into your WordPress admin dashboard.
  • Navigate to Settings > General.
  • Keep the WordPress Address (URL) as your actual installation path: http://localhost:82/_testwebsite/wordpress/ (this tells WP where its core files live).
  • Change the Site Address (URL) to your preferred root URL: http://localhost:82/ (this is what visitors will see in their browser).
  • Click Save Changes—WordPress will automatically update database entries to match these new URLs.

Step 2: Adjust .htaccess Files

Since WordPress is installed in a subdirectory, we need two .htaccess files to handle the URL rewriting correctly:

Root Directory .htaccess (C:\xampp\htdocs_testwebsite)

If there's no .htaccess file in your root htdocs directory, create a new one and add this code:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>

This tells Apache to route all requests to the WordPress installation in the wordpress subdirectory while keeping the root URL structure.

WordPress Subdirectory .htaccess (C:\xampp\htdocs_testwebsite\wordpress)

Make sure the .htaccess in your WordPress folder has the default rewrite rules (if it doesn't, regenerate it via the permalinks settings later):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /_testwebsite/wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /_testwebsite/wordpress/index.php [L]
</IfModule>

To ensure WordPress picks up the new URL structure, we need to regenerate the rewrite rules:

  • Go back to Settings > Permalinks in the WP admin.
  • You don't need to change any settings—just click Save Changes. This will flush the old rewrite rules and apply the new ones.

Step 4: Verify Your Setup

  • Visit http://localhost:82/about/—it should load your custom template page correctly now.
  • Double-check that other pages/posts also load with the root URL structure (e.g., http://localhost:82/your-post/ instead of the subdirectory path).

Important Notes

  • Ensure Apache's mod_rewrite module is enabled: Open your XAMPP Apache config file (httpd.conf), find the line #LoadModule rewrite_module modules/mod_rewrite.so, remove the # at the start, then restart Apache.
  • Avoid hardcoding URLs in your theme—use WordPress built-in functions like get_permalink() or home_url() to generate dynamic links that adapt to your site URL settings.
  • If you run into 404 errors, double-check your .htaccess file permissions (they should be set to 644) and that the rewrite rules are correct.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.28 17:42:38