Redirect & permalink problems after moving multisite to a new server

I just moved my subdomain multisite to a new server and I’m having some trouble with permalinks & redirects.

One difference post-move is that I have moved core WP files into it’s own directory /wp (see roots/bedrock folder structure.

Read More

Now when I try to access /wp/wp-admin, I am redirected to /wp-login.php?redirect_to=... which comes up as a 404 of course because that file does not exist.

However, if I comment out the multisite constants in the config, I am able to access wp-admin as a non-multisite without issue (which is how I was able to make sure I have the right .htaccess below – from Tools > Network Setup).

I have .htaccess setup with the rules instructed by WP for multisite:

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) wp/$1 [L]
RewriteRule ^(.*.php)$ wp/$1 [L]
RewriteRule . index.php [L]

The other problem is that even with multisite off, I get a 404 when trying to go to any page other than the homepage.

I’ve read that multisite stores some path info in the DB, so perhaps a search/replace is necessary?


Update 1

I was able to resolve* the problem I had with the redirect to 404 when trying to access wp-admin. This was simply due to changes that needed to be made in the database for the siteurl. I was of the understanding that this value was superceeded by the WP_SITEURL constant. This does not seem to be the case with Multisite – probably because it has to be different for each site. Once I corrected the siteurl in the options table for each site, that site would work (wp-admin could be reached).

2 Problems remain

  1. Permalinks are still not working as they should. Now that I can access wp-admin, I have gone in, and resaved to update the permalink structure which seems to have no effect. By not working, I mean I get a 404 when navigating to anything away from the front page of that site.

  2. Network admin is inaccessible via the admin bar. The URL for Network admin it’s giving me is missing the /wp directory. If I access it directly, /wp/wp-admin/network/ — it works. For some reason, the generated URLs in the admin bar are missing this and are broken.
    If I change define('PATH_CURRENT_SITE', '/'); to define('PATH_CURRENT_SITE', '/wp/');, those URLs are correct, but trying to access them fails. That does not seem like the right thing to do in this case as one would expect that to be shown under /wp-admin/network/setup.php.
    After some digging, I found that these links are generated by network_admin_url(). Essentially the responsible line of code is set_url_scheme( 'http://' . $current_site->domain . $current_site->path, $scheme ); from network_site_url().


Update 2

I was able to resolve the permalink issue. As it turns out it was actually the virtual host configuration in apache! I had AllowOverride none set for my site’s <Directory> directive, which I think was preventing any of the .htaccess rewrite rules from being applied. I should’ve realized earlier that this was the case as the 404 I was getting was from apache, not wordpress…

The only remaining weirdness at this point is the wrong url generated by network_admin_url(). Will post an answer if I figure this out.

Related posts

2 comments

  1. Well, the answer has several different ways..

    ==Method 1==

    (when you want your website permalinks to become like example.com/wp/smth )

    if so, just change this:

     RewriteBase /
    

    to

     RewriteBase /wp
    

    and in database, change all occurrences of example.com/ to example.com/wp/

    ==Method 2==

    (when you want your website permalinks to remain example.com/smth )

    Now you have A and B methods (As you say, you have made some changes to DB manually… revert them back and continue reading..). :

    A) you should move all things from wp folder to public_html folder.

    B) to use only .htaccess trick to solve the problem, and you can place all files into root>wp folder :

    <IfModule mod_rewrite.c>
    # move primary domain to subfolder
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(www.)?example.com$
    RewriteCond %{REQUEST_URI} !^/wp/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /wp/$1
    RewriteCond %{HTTP_HOST} ^(www.)?example.com$
    RewriteRule ^(/)?$ wp/index.php [L] 
    </IfModule>
    

    just change example.com and put this htaccess into PUBLIC_HTML folder (so, wordpress .htaccess should be in wp folder)

  2. All WP installs – single and MS – store URL data in the database, both for basic configurations and for paths to images and attachments in post/page content.

    You may be able to get away with simply changing the one or two values in wp_options and then be able to get back into admin. If so, save/update permalinks to rewrite the rules in .htaccess.

    But those two values can be different. WordPress Address (URL) is where WordPress resides, and for you, that will be /wp/ and not root. Site Address (URL) will be root, I assume, without the wp in the URL.

    See http://codex.wordpress.org/Moving_WordPress and esp. http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

    When you need to change URLs in the post/page content, use interconnectit.com WordPress Serialized PHP Search Replace Tool to correctly find/change URLs in the database and in serialized data.

    If you use the interconnectit script, the issue with MS is that you will have different database table prefixes for subsites, so you need to look at the database with phpmyadmin or adminer to determine the prefixes for the number of subsites you have.

Comments are closed.