So I have a site currently located in a subdirectory, like so:

http://example.com/wp

We are moving this site to a new server, and it will no longer be in a subdirectory. However, we need all the old URLs to still work, so for example if someone tries to go to http://example.com/wp/contact, it will rewrite to http://example.com/contact.

This seems like it should be simple. I’ve tried this:

RewriteEngine on
RewriteBase /
RewriteRule ^wp/(.*)$ /$1 [R=301,NC,L]

Which almost works, except it causes all the WordPress permalinks to 404 – so http://example.com/contact won’t be found even though it should be the correct URL. Does anyone know why this is happening?

Read more here: .htaccess – Removing a subdirectory from the URL


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: