• I have read lots of helpful information about this, but am still unclear on some matters.

    WordPress has been installed in its own directory /wordpress and the website address was originally test.pat.gen.nz/wordpress

    /wordpress/index.php includes statement:
    require( dirname( __FILE__ ) . ‘/wp-blog-header.php’ );

    I use pretty permalinks, so /wordpress/.htaccess comprises:
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /wordpress/
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wordpress/index.php [L]
    </IfModule>
    # END WordPress

    In order to change the url of my website to test.pat.gen.nz (leaving WordPress in its subdirectory), I copied (not moved) the above two files to the root, modifying them as follows:

    index.php:
    require( dirname( __FILE__ ) . ‘/wordpress/wp-blog-header.php’ );

    .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

    It all works as expected, so I am probably worrying over nothing, but I just want to be sure that I am correct in leaving the two files in /wordpress.

    As an aside, I understand that htaccess intercepts a call to test.pat.gen.nz/map and routes the request to test.pat.gen.nz/index.php. How does WordPress know that the intended page was ‘map’? Again, I probably do not delve too deeply into things which work perfectly well!

    Regards
    Andy

Viewing 6 replies - 1 through 6 (of 6 total)
  • If you read https://codex.www.ads-software.com/Giving_WordPress_Its_Own_Directory which is linked on the Settings > General page, you will see that you have done it correctly, although it doesn’t actually explain how it works. Be sure to save Permalinks after making changes, so that the htaccess file is updated.

    For how WordPress knows what the intended page is, that is part of the request headers and PHP populates the global $_SERVER, $_POST, $_REQUEST etc. variables, which WordPress uses to match with its internal rewrite rules to figure out what page to generate.

    Thread Starter andynz

    (@andynz)

    Thanks for the confirmation and explanation. All makes sense now.
    Andy

    Thread Starter andynz

    (@andynz)

    Just one other related question.
    I am replacing a non-WordPress website (dancescottish.org.nz) in /root
    with a WordPress site (same domain name) which is being developed in /root/wordpress.
    Thus it is currently addressed as dancescottish.org.nz/wordpress which is the site address in the WordPress settings.

    My plan is to launch the new website in /root by:
    – setting up index.php in /root
    – setting up .htaccess in /root
    – changing the site address in WordPress to dancescottish.org.nz

    However, I want to test this out before the final launch. This means doing all the above, including changing the site address in WordPress. Then, having assured that it works, reinstate the old website for a couple of weeks. Then repeat the changes which are then permanent.

    This may not seem to be a sensible approach, but there are logistical reasons why it may be necesssary.

    So, my question is: Are there technical reasons why changing the site address in WP back and forth is inadvisable? I have tried this on a test site and it seems OK.

    In fact, I concluded that I could carry out my test by just changing the two /root file and leaving the WP site address as dancescottish.org.nz/wordpress. I could still activate the website by either:
    dancescottish.org.nz
    or
    dancescottish.org.nz/website

    Andy

    That is my standard way to convert sites to WordPress. But I know it works, so I don’t do the test you are talking about. The main reason is because of the htaccess file. It says “if the file or folder does not exist, let WP handle it”. So, all those existing files and folders will be served as is, and you won’t see what you’ve developed in WP for the same thing. The final switchover must include a deletion of the old (and you typically want to have the same URL structure in place in WP or rewrites in htaccess for the things that didn’t map directly).
    The only other thing is internal links in the content. You need to remove the wordpress folder from the link. But don’t remove it from image paths, since wp-content is under wordpress (but you could change where that lives also — I usually don’t).

    Thread Starter andynz

    (@andynz)

    Thanks for the answer.
    You raised a very important point about internal links to pages since my tests had shown that these no longer work unless I remove the /wordpress part of the path. I had hoped that there might be some nifty way of leaving the path as it is, but I now know that this is not the case.
    Fortunately there are very few of them.

    Regards
    Andy

    Thread Starter andynz

    (@andynz)

    Your advice has been really helpful, so I have one more question before I carry out the migration (on a real website – not my test one).
    WordPress has been installed in /root/wordpress and the settings are:
    WordPress Address: https://dancescottish.org.nz/wordpress
    Site Address: https://dancescottish.org.nz/wordpress
    Permalinks: Postname

    /root/wordpress includes the required .htaccess and index.php files
    Website addressed as dancescottish.org.nz/wordpress works fine as it is.

    If I display a page in the admin panel, say with title ‘Class Guidelines’ the permalink is displayed as expected
    Permalink: https://dancescottish.org.nz/wordpress/class-guidelines/ ?

    The question is: When I change the site address in WP settings to:
    Site Address: https://dancescottish.org.nz
    will WP automatically change all the permalinks to exclude /wordpress
    and take care of any links which have been defined in the menu.

    If so, I just need to correct any hard-coded links in my pages, tablepress etc and. of course, set up modified versions of .htaccess and index.php in /root.

    And, before you ask, /wordpress and the database will be backed up first!

    Regards
    Andy

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘htaccess in root and subdirectory’ is closed to new replies.