Only a wordpress group of user can access to a folder using .htaccess - wordpress

I don't know a lot about .htaccess.
I have a web with Wordpress and I made a part private only for subscribers. I have installed a couple of Wordpress plugins to control the access to that page. The problem is that the "private" page links to a folder where I have a lot of .html pages. That is the folder I want to protect. I have used the http_refered in the .htaccess but I know it is very easy to hack it.
Is there any way to write in the .htaccess file a command that check the Wordpress user file and see if the user belongs to the "suscriber" group?

I suggest to protect the private page with password (this is common feature in Wordpress) and do not mess with the .htaccess file.
Anyhow, the is no way to tell the Apache (because the .htaccess is applied from it) that this or that user is registered or approved user. This can be done on different level - PHP and/or Wordpress logic.

Related

Wordpress - Moving website admin section

I have successfully moved a wordpress site from /test directory to the root, so now the website url looks like www.example.com. Fine.
However the admin section (wp-admin) still points to /test directory and so the url looks like www.example.com/test/wp-admin/...
How can I make it like www.example.com/wp-admin/...?
Please notice that I'm not interested in a simple redirection (now the customer is able to access the admin section with www.example.com/wp-admin, but then he's redirected to www.example.com/test/wp-admin/..., and it's not what he wants.
Thanks in advance
Everything is documented in http://codex.wordpress.org/Moving_WordPress
You may need to change many URLs in post/page content; if so, see https://github.com/interconnectit/Search-Replace-DB as suggested in the above Docs.
There is no need to create a new Wordpress install.
Also see http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory#Using_a_pre-existing_subdirectory_install if you want to keep core Wordpress files and folders in a subfolder, but have the site appear to be at root for the end user.
You should not move wordpress this way. Here is what you do:
Install Clean Wordpress Installation on the new domain.
(www.original.com)
Use a plugin* to make back-up on your test domain.
(www.original.com/test/)
Install plugin* on the new domain, and restore back-up from test
domain. (www.orignal.com)
Update your style.css, header.php, index.php & footer.php if it
contains hard written links to your test domain.
You cannot simply move a wordpress installation - as most entries, links etc. are stored in the database. If you move folders in your ftp they will still point to the old database. This is why you have to duplicate your site, where the database entries will be automatically updated to your new site domain. Hard written links in any theme php files will have to be updated.
Although your problem depends on how your pointers/sites are set-up in c-panel. If you have to change pointers for your directory, you might have to back-up your website and upload it to a different domain so your new site can access the restoration back-up file via http request.
*Plugins such as wp clone, duplicator.

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.
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.
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 On\nRewriteRule ^(.*)$ site.com$1 [R=301,QSA,L]\n");
echo("<code><pre>-------- included file starts here\n");
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.
I am sorry for your situation. What is the hosting company (will keep this in mind if I ever use them). To try to help:
Do you have access to CPanel? Most hosting providers give it out of the box. Cpanel has a file manager.
Research Wordpress file managers (http://wordpress.org/plugins/wp-filemanager/)
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/

Secure uploaded files in Wordpress

I have site based on Wordpress. Only logged user can see posts, sites, and files (I use s2member plugin).
I have problem with disabling access to files for unlogged user.
I upload files, attach it to post. Only logged user can see post and attachements.
The problem is that unlogged user can download files directly (e.g. http://my-site.pl/files/secret_file.pdf).
How can I prevent this, some plugin, .htaccess?
My site is on shared hosting i have access only via ftp.
There are potential solutions, but none stands out in practice -- each has its own set of thorns.
There are commercial plugins that implement access restriction on part or all of your WP site. Some allow to restrict files, some don't. Amember is one of the more established players in that arena. (I cannot recommend their offer, however. Amongst other problems I ran into, it didn't play well on a multi-server setup.) There probably are some free plugins that do the same since I last checked.
If you decide to code something yourself, there are multitudes of options. Three of them include:
Serving the file using php instead of Apache, and requiring the user to be logged in before serving the file. It works. And it's relatively easy to set up if you decide to be sloppy. It's not so easy if you want to set it up correctly: think partial files that need to be resumed, etc.
Conditionally serving the file using Apache. In essence, you create a user-specific file in a token folder, and you store the name of that file as a cookie when the user log in. Then, have Apache rewrite rules deny access if the corresponding file isn't present in the token folder. This is not easy to set up
Not restricting files at all and leaving things the way they are at the moment: a link to a publicly available file that only members can see. The rational here is that no matter how well you restrict access to your pdf, it'll end up on a torrent site or a download site somewhere if a disgruntled user decides to share it.
Use this in .htacces. this allow user to download or view only .gif, .jpg,.jpeg,.png and .bmp files.
if you don't want to allow this then remove the line "Allow from env=let_me_in"
I hope this will work.
# BEGIN WordPress
<IfModule mod_rewrite.c>
# If the URI is an image then we allow accesses
SetEnvIfNoCase Request_URI "\.(gif|jpe?g|png|bmp)$" let_me_in
Order Deny,Allow
Deny from All
# Allow accesses only if an images was requested
Allow from env=let_me_in
</IfModule>
# END WordPress

wp-admin and wp-login.php - 404 error for those who do not administrator (wordpress + htaccess)

I try to hide the traces as wordpress on my website for security reasons. Does anyone know how to create a rule using htaccess, according to which a third party user (with a different ip) redirected to on /404.php if he visits the wp-admin and wp-login.php ... I've seen third-party plug-ins (?) To address this problem, but I do not want to create an extra load on the CMS.
you can use simple redirect in .htaccess like this
Redirect 301/wp-admin/ http://www.yourwebsite.com/404.php
But if you're trying to completely hide wordpress it requires a little bit of technical work...what I did in mine, is search every files in the wp-include and wp-content folder as well as the root folder that contained the wp-login.php and /wp-admin/somefolder words, and change everything to a file or folder to a name of your choice that no-one can guess. Although you have to be very careful as not to change an important code there...

Wordpress: prevent navigating to files in content folder unless logged in

So I'm working with an installation, and have files in my wp-content/uploads folder. I want to prevent people from navigating to it directly, or accessing it at all (including videos called in a podcast), unless they are logged into the site.
It this a simple htaccess thing? I'm not even sure where to start.
Add
Options All -Indexes
to your .htaccess file after the # END WordPress line.
It will prevent people from browsing your folders and display a forbidden message if they try. See:
http://catrabbit.com.au/wp-content/uploads/2010/10/
I misinterpreted the question. Sorry.
To clarify:
This stops everyone (logged in or otherwise) from browsing your folders. I'm not sure why do want to allow logged in users to browse the uploads folder in the first place...
Found a plugin to handle this:
http://wordpress.org/extend/plugins/private-files/

Resources