Wordpress installed Subdirectory - Now lots of existing hyperlinks are not working

I installed Wordpress in a subdirectory for development - the subdirectory is /site/. When we were ready to go live we followed the instructions here http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory#Using_a_pre-existing_subdirectory_install to make the site live at the root URL. This has worked fine.

However what I'm struggling to fix is that many of the hyperlinks existing in the site now give 404 errors. Some pages redirect, but if they have a parent, then they don't redirect.

examples:
mydomain.com/site/specials
> successfully redirects to mydomain.com/specials

But
mydomain.com/site/contact-us/request-a-quote/ gives a 404 error.
It should redirect to mydomain.com/contact-us/request-a-quote/ but it doesn't.

It seems any previously built hyperlink that points to a page which has a parent page, ends up as a 404 error.

Options:
1) We could use a Search and Replace option to remove /site/ from each URL ... however this will break all images at the same time.
2) We could manually update the links ... but there are way too many.
3) Is there an .htaccess solution?

I have tried to solve this by adjusting the .htaccess file to redirect URLs with /site/ in them to the root directory. However if we do this we need to exclude wp-admin, wp-content, wp-includes, /site/index.php and others. Whatever I have tried so far fails.

And there is nothing in the official documentation about what to do with existing hyperlinks when moving changing a subdirectory install to displaying at the root domain. (And the really weird thing is that I tested this when I first when live with the site, and all the redirects worked fine, including the ones with parent pages, but it has since stopped working, and I don't know why).

Here is my .htaccess contents:

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

</IfModule>

# END WordPress

Can someone provide lines of code that will work?

Thanks
Josh

  • Milan
    • WordPress Wizard

    Hello @Josh,

    Hope you are doing great ! :slight_smile:

    There are three ways through which you can solve this issue . Go with first solution first if it doesn't work for you try to apply second if second doesn't work then finally go with third.

    #1)Try re-saving your permalinks.

    #2)Try resetting your permalinks to the default setting and then changing them back to your settings .

    #3)Add this code at the end of function.php of your current active theme then refresh your page and finally remove added code.

    global $wp_rewrite; $wp_rewrite->flush_rules();

    Note :- If you follow step three than do not forgot to remove code which is added to function.php after refreshing your website page.

    I hope this will help you.

    Please let me know if there is anything else I can help you with.

    Enjoy wpmudev. :slight_smile:

    Warmest Regards,
    Milan Savaliya.
    Support Staff (WPMUDEV).

  • Josh
    • Design Lord, Child of Thor

    Hi Milan. Thanks for those options. Unfortunately none of them solved the issue. I tested each one, but the problem still exists.

    So
    mydomain.com/site/specials
    successfully redirects to mydomain.com/specials

    But
    mydomain.com/site/contact-us/request-a-quote/ gives a 404 error.
    It should redirect to mydomain.com/contact-us/request-a-quote/ but it doesn't.

    Any other ideas on what might be causing it and how to solve it?
    Thanks

  • luke
    • Flash Drive

    Any chance of responding agian Milan, I'd be interested in the answer to Josh's last question.

    I've been trying to figure this out for a while now, I can get the main pages to work correctly but as Josh says, pages with a parent won't link and end up at a 404.

    Like:

    http://www.domain.com.au/site/product - work s& gets to - http://www.domain.com.au/product

    http://www.domain.com.au/site/shop/product - leads to 404 because the sub directory "site" isn't removed like it is with main pages.

    Thanks,
    Luke

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.