Editing .htaccess without FTP access through WordPress

I have no access to my FTP but I’m able to edit the web through WordPress. Is there any way I could perhaps generate the .htaccess file through the admin framework? I know there might be a plugin to do that, but bear in mind I have no FTP access and the plugins require it to be installed.

I need the .htaccess file to redirect the user to another site.

Read More

I know this might strike you as weird and stupid, but this is due to the company’s central decision to keep the site hosted by, I guess, a “friendly” hosting company. There’s no way of recovering the login/password for FTP, so this might be the only solution.

Please, try posting constructive comments only, no “contact the hosting company”. If I could, I would.

Related posts

Leave a Reply

3 comments

  1. If your hosting company has set up wordpress correctly, then there is no way to do this, because unix permissions should make .htaccess read-only to the owner of the web server.

    If the company has not done this, and if you have a way to change the templates, you might have success by creating a template that contains php code to open and write the .htaccess file.

    Sample code to be put at the top of the header.php:

        echo 'Current dir: ',getcwd(),"<br>n";
        if ($handle=opendir('.')) {
                while (($file=readdir($handle))!==false) {
                        $ok=(is_writable($file) ? "ok" : "can't write");
                        echo "file '$file': $ok<br>n";
                }
                closedir($handle);
        }
    

    This is to test you’re in the root directory of your wordpress installation. It should give you the current directory, a list of all files in that directory (expect .htaccess, index.php, and various wp-* files), and their writability.

    Once you’ve checked everything is correct, add

    file_put_contents('.test', "RewriteEngine OnnRewriteRule ^(.*)$ site.com$1 [R=301,QSA,L]n");
    echo("<code><pre>-------- included file starts heren");
    include(".test");
    echo("-------- included file ends here</pre></code>n");
    

    to the php code. This writes to a test file and includes it so you can check if everything is ok. When you’ve checked the file contents, replace .test with .htaccess.

    WARNING: You should be VERY sure about the content of .htaccess. file_put_contents doesn’t append the new string, it overwrites the whole file. Once you’ve written a bad .htaccess file, you might not be able to ever change it again, because the web server will redirect you to the new site instead of executing the script on the old site.

  2. How to edit wordpress .htaccess file from hosting Cpanel: If you are currently unable to login in your wordpress dashboard, or facing 500 internal server error. There is 90% possibility that you were editing your .htaccess file from your wordpress dashboard. In this situation you can only fix your wordpress .htaccess file by editing it from cpanel. Editing .htaccess file from wordpress dashboard is little risky with .htaccess editor plugins. If you will implement any wrong code then you might face 500 internal server error and your site might crush. So first you should take a backup of your existing .htaccess file before editing it. If you have a backup of your wordpress .htaccess file then you can upload it through your hosting cpanel also.
    https://howtoways.com/how-to-edit-wordpress-htaccess-file-from-hosting-cpanel/