Support » Installing WordPress » How to install WP to subfolder while homepage gets redirected

  • Hi guys 🙂

    As the title says, I want to install WP to a subdirectory (copy, to be specific) e.g. http://www.example.com/test where my site will be accessed by everyone who knows the link (basically where I can develop my site). But at the same time I want that everyone who accesses the site http://www.example.com gets redirected to a different page.

    How can I do that?

    Currently I have my WP installed in the root directory and also have that content copied from the root to the /test subfolder.
    I set a rule in htaccess that redirects everybody who goes to the root page (www.example.com), but this way I can’t access the homepage either.

    That’s why I would like to do it like I said before, but I’m not sure how to do it and I don’t want to mess up anything.

    Thanks in advance!
    Dave

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hello, Michael,

    thanks for your quick reply.

    So I already have my WP site in /test subfolder. So basically I just need to change the url in WP settings in both fields to http://www.example.com/test. Is that correct?

    Then I will have 2 htaccess files, one in the root and second one in the /test subdirectory. To get everybody redirected from the root site (www.example.com) I will just paste the code you gave me into the htaccess file in the root. Am I right?

    When all this is done, I can remove all the WP content from the root I previously had there, leaving just the htaccess file for the redirection?

    Michael

    (@michaelvdberg)

    If you have everything what you want from the root installation, you are safe to delete that installation. When you delete this installation, you have to create a new (clean) .htaccess file in the root folder. In the root .htaccess file you put the redirect 301 (or 302) code in it. (301 = permanent redirect / 302 = temporary redirect).

    If you have change the URL’s, it’s should work correctly by domain.com/test/wp-admin/.

    Did you know that you could install a dev installation in a subfolder? (Mostly every webhosting support subdomains). You can create something like dev.domain.com. So you can create a “Under construction” page in the root of the domainname. For example with a fresh WP installation and Under Construction plugin. So you are able to move your dev installation to the root folder when you are finished with the development.

    I would like to recommend you to have a back-up first before you changed something!

    If you have any questions or if you need help, please let me know!

    Thanks again, Michael.

    I will try my luck with the method I’ve already in progress. If it won’t work I will try the one you suggested.

    So basically after migrating the content to the subfolder /test I will create a blank htaccess where I will put just the redirection code, nothing else. I don’t need to copy the htaccess, right?

    I will try it during the weekend, so I would really appreciate if this topic could be open till then, if I had any questions. You’ve been really helpful so far, helping my understand how it works. Thank you!

    Michael

    (@michaelvdberg)

    Don’t worry and you are welcome! If you need any help, please add here a new reply.

    You can try if you could add the redirect at the end of the .htaccess file and check if your redirect works and that you are available to access your WordPress installation in the test folder. Otherwise you should clean the root .htaccess file and add only the redirect 301 or 302 code in it.

    So before you start, make sure you copied (or save it somewhere) the .htaccess files to your local harddrive, for a back-up if something goes wrong.

    dave517

    (@dave517)

    Hello Michael,

    so finally after a long time I got to do it, but for some reason it is not working.

    I’m not sure if it’s possible, but could we find a faster way of communication to resolve my problem? Would it be too much to ask?

    dave517

    (@dave517)

    Thanks for being really helpful. I tried different versions of htaccess and it seems like I managed to solve the issue. It is working for now at least. Hopefully, I won’t find any errors.
    I will copy my htaccess files if somebody had the same issue.

    My root htaccess
    RedirectMatch 301 ^/$ https://www.wheretoredirect.com

    My subfolder htaccess

    
    # 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
    

    Probably the issue was with the previous commands in the htaccess files I had. So I had to play around a little to find this solution (which now seems really easy and straightforward).

    Thanks again for your help Michael! I wouldn’t have done it without you!

    • This reply was modified 6 months ago by  dave517.
    • This reply was modified 6 months ago by  dave517.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to install WP to subfolder while homepage gets redirected’ is closed to new replies.