I have copied a wordpress site over from a server I need to work on and set it up on localhost, the wordpress folder is set up as a subdirectory of root.

My only problem is my links are redirecting to the root instead of the wpfolder eg. and file paths do not have the wpfolder name in them.

Example:

ht.p://localhost/wpfolder/wp-content/themes/tbt/_inc/js/functions.js

Should be:

ht.p://localhost/root/wpfolder/wp-content/themes/tbt/_inc/js/functions.js

I have followed all the instructionss from the codex https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory#Using_a_pre-existing_subdirectory_install and have everything working except I have been struggling to get my links and files to redirect to the right filepath.

I have saved general settings, refreshed permalinks and restarted the server in that order. I have also confirmed the htaccess is being read and the database is being read fine with all posts available in wp-admin.

The confusing thing is that even though the original site on the server has wp installed in a subdirectory I dont see how its redirecting. The site structure of the local copy is as follows:

/localhost/site_root/wpfolder

and original:

user@domain/public_html/wpfolder

When exporting the db I have set the addresses are as follows:

SITE ADDRESS
remote: //www.domain.com,
local: //localhost/siteroot/

WP ADDRESS
remote: /home/siteuser/public_html,
local: /siteroot/wpfolder
(I dont get why this doesnt point to the subdirectory on the original site?)

htaccess at remote root:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} /order-online/order-now/ 
RewriteRule ^(.*)$ https://www.sitename.com.au/order-online/order-now/$1 [R,L]


# 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

and my local htaccess at the root written automatically after migrating the db and saving all settings in wp-admin:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} /order-online/order-now/ 
RewriteRule ^(.*)$ https://www.originalsitedomain.com/order-online/order-now/$1 [R,L]


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

# END WordPress

My local index.php at the root (same as remote):

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

Currently for example instead of my links taking me to localhost/site_root/link there are going to localhost/link and 404’ing.

I haven’t been able to get this to work as I dont fully understand it:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^localhost/siteroot$
RewriteCond %{REQUEST_URI} !^/wpfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wpfolder/$1
RewriteCond %{HTTP_HOST} ^localhost/siteroot$
RewriteRule ^(/)?$ wpfolder/index.php [L] 
</IfModule>

But it is not in the htaccess of the original site anyway (why i dont understand). Im all out of ideas for the love of jeebus can anyone help with the rewrite above or suggest what I may be doing wrong?

Let me know if I can provide more info.

Thanks.

Read more here: Rewrite rule for wordpress site installed in subdirectory (not a multisite)


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: