WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Subdirectory install with access from root (3 posts)

  1. C W
    Member
    Posted 2 years ago #

    I'm attempting to run WordPress from the root while keeping it in its own subdirectory. I've essentially followed the procedure under "Moving a root install to its own directory" in the Codex, the only difference being that my core files were already in the subdirectory, which makes Step 6 unnecessary.

    This has worked exactly as intended. Now, the /wordpress bit of the URL is stripped out and it looks to the end user as though they're browsing http://mysite.com instead of http://mysite.com/wordpress.

    Problem: I don't want all the old links to break. If an external site linked to http://mysite.com/wordpress/2011/06/an-article-slug, they're now going to get a 404 page. I'd much prefer that they get automatically (301-)redirected to http://mysite.com/2011/06/an-article-slug, which is the new location of the file.

    I've tried to insert a rule into the .htaccess files [N.B. the procedure in the Codex means that there are now two .htaccess files: one in the root and one in the subdirectory] to bring about this behaviour, but it is still failing to do the redirection (and is therefore delivering 404s). Here's the .htaccess:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /wordpress/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wordpress/index.php [L]
    
    RewriteBase /
    RewriteRule ^wordpress/(.*)$ /$1 [R=301,NC,L]
    </IfModule>
    # END WordPress

    The last two lines before the end of the if statement are my attempt to get the redirection to work.

  2. s_ha_dum
    Member
    Posted 2 years ago #

    Which .htaccess is this?

    Have you tried putting that "^wordpress/..." rule above the normal WordPress ones? .htaccess rules execute line by line. Order does (sometimes) matter.

  3. C W
    Member
    Posted 2 years ago #

    Yep, worked that out a couple of hours after posting! It's now working fine.

Topic Closed

This topic has been closed to new replies.

About this Topic