How to Run WordPress from a Subfolder (e.g., /m)

You can install WordPress into a subfolder such as /m instead of the web root (/public_html) and configure it to work properly either:

  • From the subfolder itself (https://example.com/m), or

  • From the root domain (https://example.com), even though it's physically located in the subfolder.

This article explains both methods.


Option 1: Access WordPress from the Subfolder URL (https://example.com/m)

Step 1: Upload WordPress to a Subfolder

Place all WordPress files inside a subfolder under your root directory.
Example path: /public_html/m/

Step 2: Set WP_SITEURL and WP_HOME

Edit your wp-config.php file and add the following lines before the line that says /* That's all, stop editing! Happy publishing. */:

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

Alternatively, using const:

const WP_SITEURL = 'https://example.com/m';
const WP_HOME = WP_SITEURL;

Replace example.com with your domain and m with your subfolder name.

Step 3: Fix Permalink Issues (Pretty URLs)

If you are using pretty permalinks, create or update the .htaccess file inside the /m folder:

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

Then go to WordPress Admin → Settings → Permalinks and click Save Changes to flush the rewrite rules.

Result

Your site will be fully accessible at:
https://example.com/m


Option 2: Access WordPress from the Root URL (https://example.com) but Keep Files in Subfolder

This approach lets you keep WordPress files in a subfolder while serving the site from the root domain.

Step 1: Upload WordPress to a Subfolder

Upload all WordPress files into /public_html/m/ (or any subfolder).

Step 2: Set WP_SITEURL and WP_HOME

Add the following lines to wp-config.php:

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

Step 3: Copy and Edit the Index File

  1. Copy these two files from the /m folder to the root /public_html/ directory:

    • index.php

    • .htaccess

  2. Edit the copied index.php and change:

    require( dirname( __FILE__ ) . '/wp-blog-header.php' );
    

    to:

    require( dirname( __FILE__ ) . '/m/wp-blog-header.php' );
    
  3. Update the .htaccess file in the root folder to handle permalinks:

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

Result

Users will visit the site at:
https://example.com
Even though WordPress files reside in /public_html/m


Additional Notes and Troubleshooting

  • Do not change the WordPress Address or Site Address from the admin panel after configuring wp-config.php, as it may overwrite your settings.

  • Most plugins and themes will work properly unless they use hardcoded URLs.

  • If permalinks break after moving WordPress, re-save them from Settings → Permalinks.

  • Ensure SSL is properly set if your site uses HTTPS. Both WP_SITEURL and WP_HOME must use https://.


Conclusion

Running WordPress from a subfolder can keep your root directory clean or serve multiple apps under one domain. Choose the configuration that fits your needs and follow the steps carefully.

If you're unsure which setup is best for your use case, contact support with your folder name and target site URL.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to restrict direct root access in Linux

We can do it just in two steps. Step One: At first we will create new root user as follows (for...

How to extract .tar.gz files in Linux/UNIX OS

A tarball is a group of files that are bundled together using the tar command. Use the...

How to add welcome message when SSH start?

You need to change the contents of /etc/motd. Unfortunately, by default, /etc/motd is a link to...

How to change root password when SSH logged in

Run the following command: passwd Now type your new passwordOnce done, retype new passwordDone!...

How to install Pinguzo on any Linux/UNIX OS

Login to Pinguzo panel using Softaculous account or create an account of Pinguzo To add new...