• Whitegoodshelp

    (@whitegoodshelp)


    Hello

    I’ve been running my WordPress site for 10 years. It’s in a sub directory called WordPress. I’ve just moved to https: and whilst troubleshooting lost social shares I’ve realised I’ve become totally confused about where my htaccess file should be.

    I’ve ended up with 2, one in the root and one in the wordpress folder. However, they are both virtually the same (Something went wrong ages back and I found it was fixed when I duplicated the file in both places).

    I suspect that I do not need duplicated htaccess files but maybe I do need 2? But with one maybe just doing a small function?

    I need my pages to be accessible without the /wordrpress/ part, which is how things are. But can you please tell me where I should have the main htaccess and do I need one in each location?

    Many thanks

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter Whitegoodshelp

    (@whitegoodshelp)

    I’ve remembered that a WordPress help file told me to copy the htaccess file (not move it). So that means 2 htaccess files should exist. Can you clarify if the need to be exact duplicates though – or was the directive to copy (and therefore duplicate) only assuming a clean install with just the basic wordpress rewrite rules in place?

    Once both htaccess files are there do any changes (such as a redirect) need to be done in both files? It seems a bit cumbersome to have to edit 2 files each time you change something?

    Andy

    barnez

    (@pidengmor)

    There should be a .htaccess file with the WordPress permalinks directives in the *same* directory level as the wp-content, wp-admin, wp-includes directories. In your case this sounds like

    
    /username/
             /wordpress/
                        /wp-admin/
                        /wp-content/
                        /wp-includes/
                        .htaccess
                        .... other files
    

    The WordPress permalink directives look something like this (yours may be different):

    
    # 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
    

    Now you can also find .htaccess files in other directories where they perform security tasks, among others (hosts and plugins sometimes add them).

    I would inspect and compare the contents of both files. If they both contain the WordPress rewrite rules then make a copy of the file located in the directory *above* /wordpress/. Now you can delete it and test the site. Making a copy of any file you delete is crucial as it allows you to simply drop the file back into place if anything goes wrong!

    • This reply was modified 8 years ago by barnez.
    Thread Starter Whitegoodshelp

    (@whitegoodshelp)

    Many thanks Barnez. I can confirm that I have the code you quote in both htaccess files. I also have dozens of url redirects,compression settings, caching settings and various other things in both files.

    Since reading that I needed to copy (not move) the htaccess from the wordpress directory to the root I’ve assumed both files need to be the same – hence the duplicate.

    This means every time I’ve added anything to htaccess I’ve had to do it in both files which has always struck me as strange.

    I just deleted the # Begin WordPress section from my root htaccess and it produced a server error
    I replaced it and deleted it from the wordpress folder htaccess file and the site appears to work OK

    barnez

    (@pidengmor)

    Sounds like you have found out which version is being used. Good job! I imagine some of the redirects remove /wordpress/ from your urls.

    Thread Starter Whitegoodshelp

    (@whitegoodshelp)

    Thanks. I’ve just deleted all the 301 redirects from the htaccess in the wordpress folder, the ones in the root htaccess folder do the job.

    I knew it was not necessary to totally duplicate the htaccess files. Unfortunately WordPress’s instructions on how to have a wordpress installation in its own folder and stripping out the /wordpress/ from urls just says to copy the htaccess from the wordpress folder to the root which gave me the impression they should be duplicated.

    Many thanks

    Andy

    barnez

    (@pidengmor)

    Yeah, the codex is always a work in progress. Happy to hear you have things sorted.

    Cheers!
    Damian

    Thread Starter Whitegoodshelp

    (@whitegoodshelp)

    Just to update. Today I found that some of my links were broken. Old links that referred to the full location of WordPress ie in the wordpress folder. They gave a server error and didn’t even fetch a proper 404 not found page.

    I copied back the # Begin WordPress code and they were restored.

    It seems that this code needs to also be in the wordpress folder as it strips out the /wordpress/ from links.

    For example some of my old links were like this –
    https://www.mywordpresssite/wordpress/NameofArticle/

    The wordpress code strips out the wordpress folder and takes people to –
    https://www.mywordpresssite/nameofArticle/

    Andy

    barnez

    (@pidengmor)

    Thanks for the update. Good job that you checked those links. I suppose you either live with the current arrangement or move WordPress to the root directory and then update all the database urls from https://www.mywordpresssite/wordpress/ to https://www.mywordpresssite/ using a plugin like better search and replace. Is there a specific reason for the current setup?

    Thread Starter Whitegoodshelp

    (@whitegoodshelp)

    I think I just installed into wordpress folder for neatness. I knew there was a possibility of running other things (eg forums) and wanted things neatly in their own folders.

    Go it. Well, looks like you’ve gone the full circle, back with 2 x .htaccess files and fully clear of why they are both needed. Gotta love experiential learning ??

    Thread Starter Whitegoodshelp

    (@whitegoodshelp)

    Yes but I’ve also learnt that I don’t need to duplicate everything in both files as I had been doing. Apparently I need the # Begin WordPress stuff, but most of the other stuff I had in there like 301 redirects and more have now been deleted and everything works OK. Many thanks for your help.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Confused about htaccess location’ is closed to new replies.