Support » Installing WordPress » Serve wordpress at root for existing subdirectory install

Viewing 4 replies - 1 through 4 (of 4 total)
  • Looking at another site I have set up in a similar way, here’s how I think this should work:

    In the database, all the stored urls should be of the form:
    www.example.com/subdirectory/ EXCEPT the siteurl, which should be without the subdirectory.

    The .htaccess file should look like this:

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

    The root site index.php should have:
    require( dirname( __FILE__ ) . '/subdirectory/wp-blog-header.php' );

    While the subdirectory index.php should have:
    require( dirname( __FILE__ ) . '/wp-blog-header.php' );

    At least, that’s how my other site is set up, and it works. But not here.

    This will redirect your domain from your account’s root to its actual location anywhere:

    # BlueHost.com
    # .htaccess main domain to subdirectory redirect
    # Do not change this line.
    RewriteEngine on
    # Change example.com to be your main domain.
    RewriteCond %{HTTP_HOST} ^(www.)?example.com$
    # Change 'subdirectory' to be the directory you will use for your main domain.
    RewriteCond %{REQUEST_URI} !^/subdirectory/
    # Don't change the following two lines.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # Change 'subdirectory' to be the directory you will use for your main domain.
    RewriteRule ^(.*)$ /subdirectory/$1
    # Change example.com to be your main domain again.
    # Change 'subdirectory' to be the directory 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.)?example.com$
    RewriteRule ^(/)?$ subdirectory/index.html [L]

    Then along with that, it sounds to me like you will need the couple of temporary lines either in wp-config.php or your theme’s functions.php to tell your database to use http://www.mysite.com …but I do not have those handy at the moment. Also, I believe you will need to change that last line above to index.php.

    Thanks for this.

    I think when you properly install WordPress to a subdirectory, it does the redirection without using a RewriteRule like your example in the .htaccess file, though. I have several other sites installed in subdirectories on other URLS, and their .htaccess files are as I posted, without the subdirectory redirect. Thoughts?

    OKAY: so, hardcoding the siteURL and Home by adding these lines to the wp-config.php file:
    `define(‘WP_HOME’,’http://www.example.com&#8217;);
    define(‘WP_SITEURL’,’http://www.example.com/subdirectory&#8217;);’

    SOLVES the admin redirect, and now hey presto the site loads correctly.

    I’m out of time to work on this today, but my suspicion is that the plugin WP-Supercache, which also writes RedirectRules to the .htaccess file, is not picking up the cues and is interfering with whatever WordPress is doing.

    I’ll post back whatever I figure out. But it’s nice to know I can fix the admin redirect loop by adding those lines to the wp-config.php file.

    I think when you properly install WordPress to a subdirectory, it does the redirection without using a RewriteRule like your example in the .htaccess file, though. I have several other sites installed in subdirectories on other URLS, and their .htaccess files are as I posted, without the subdirectory redirect. Thoughts?

    I might not get this put into words well, but yes, I believe there is a difference-of-approach here since I began learning things much later in the game than others, and also from the vantage point of *beginning* with a Primary Domain being redirected to sub-folder without having to modify anything at all within WordPress. So, I have *never* had to do anything I call “tricky” in order to relocate a domain, but my observations here in the forums cause me to believe what I call “tricky” used to be the only way and is still something necessary for people developing locally. For a Primary Domain, I use the above code to redirect it from public_html to wherever it might actually be, and for Add-Ons and sub-domains, I use cPanel to assign and point them…and every domain I have (other than my sub-domain) in whatever sub-folder has nothing other than https://thisdomain.com in each of the boxes at Dashboard > Settings > General and I have no broken links. So then, and where what I have going is useless to some folks, it seems all the stuff I call “tricky” at least can be completely unnecessary for certain others.

    Edit: There is at least one caveat here since I have just (yesterday) discovered BulletProof Security (mentioned only as an example here) uses “actual server path” for certain things within itself, so one of the domains I had moved to a different (renamed) folder actually *did* have a broken link within the internal code written by that plugin. Re-installation of that plugin can easily fix that, of course, but I am first going to try a database edit.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Serve wordpress at root for existing subdirectory install’ is closed to new replies.