.htpasswd in subfolder on Wordpress Install - wordpress

I have a wordpress install at the root of my home folder, and I have a subfolder that I am trying to protect with an .htaccess based login. In the root there is an .htaccess with these rules:
# 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
Then in my subfolder I have this .htaccess
<IfModule mod_rewrite.c>
RewriteEngine off
</IfModule>
AuthName "MySQLDumper"
AuthType Basic
AuthUserFile "/home/freegame/public_html/msdump/.htpasswd"
require valid-user
With the Wordpress rules active, access the subfolder causes a 404 error. When I delete the wordpress rules, it works fine. Any ideas on what I've done wrong?

Your method will work only for files. For protecting directory you have to perform an additional step. Modify the htaccess file in the your site’s root directory and add the following above the #Begin WordPress comment.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/(failed_auth\.html).*$ [NC]
RewriteRule . - [L]
</IfModule>
This will stop WordPress from giving a 404 error code when you try to access your password protected directory. Instead it will give a 403 (authorization required) and prompt you for a valid username/password instead to access it.
Source: Dreamhost

Related

.htaccess url rewrite does not work on GoDaddy Shared Server, Apache 2.4.3 - 404 error returned

I've created an .htaccess file. A test on madewithlove's htaccess tester (https://htaccess.mwl.be) said the URL rewrite is correct, but a live test returns a 404 error.
URL I want to rewrite:
http://example.com/folder1/folder2/word123 // To redirect to
https://example2.com/en/?key=word123
My .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
# BEGIN Part that is not working
Options -Multiviews
RewriteEngine On
RewriteBase /
RewriteRule ^folder1/folder2/(.*)$ https://example2.com/en/?key=$1 [R=301,L,NE]
# End part that is not working
I am using GoDaddy shared hosting with Apache 2.4.3-25. The WordPress lines work. If they are removed, then Wordpress Page and Blog links break.
I recognize this question resembeles URL Rewrite keeps returning 404 Error, but martoio redirected from an existing file.
I tried both Siraj Khan and Gautam Jha's solutions offered on Friendly URLS / URL Rewriting using .htaccess on godaddy shared server to no avail.
I'm at a loss for what to do, so your help is greatly appreciated.
This is the revised version after including neokio's suggestion:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
</IfModule>
# END WordPress
# BEGIN Part that is not working
Options -Multiviews
RewriteEngine On
RewriteBase /
RewriteRule ^folder1/folder2/(.*)$ https://example2.com/en/?key=$1 [R=301,L,NE]
# End part that is not working
My .htaccess file, which was located in the public_html folder, base url, was being overridden by another .htaccess file located in folder1.
Check if an .htaccess file is located in a subfolder, because the .htaccess file in the deepest subfolder takes priority.

subdomain .htaccess & htpasswd files affecting root directory

I have built a site for a client using WordPress. The site was built on the subdomain http://staging.url.com. Using Plesk I restricted access to the 'staging site' using a password
When site was completed I downloaded 'staging site', duplicated the database and re-uploaded to http://www.url.com. Everything works ok apart from when I'm logged into the wordpress admin, I get the Authentication Required pop-up, saying http://staging.url.com requires a username and password.
I cannot find any file that would be telling the server that http://www.url.com is http://staging.url.com and prompting the Authentication Required pop-up.
Can anyone help?
Many thanks,
Elliott.
Current http://staging.url.com htaccess file
# 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
AuthType Basic
AuthName "restricted area"
AuthUserFile /var/www/your-url/.htpasswd
require valid-user
Current http://www.url.com htaccess file
# 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
I think your files it is loading from your staging website
Go to inspector on your browser and check if any image or files are loading from your staging in the production website.

wordpress site ignoring sub directory when htaccess present

To begin I did not setup the website I am currently working on, and I am not very familiar with the wordpress setups. I have been called in on their site to add an admin section to this site which uses a Wordpress configuration. If I add a sub-directory, I can access the sub-dir via web just fine. The problem comes when I add a .htaccess to that subdirectory for Auth purposes. When I do this, and try to access the sub-directory, it errors to a 'Page Not Found'.
Can someone please help? I assume it is something with the Wordpress .htaccess file provided below:
# 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
UPDATE
When the .htaccess in the sub directory is blank, I can access the sub-directory via web just fine.
.htaccess (when filled out) in sub directory is below:
AuthType Basic
AuthName "Sphere"
AuthUserFile "/path/to/htpasswd"
require valid-user
I just tested a setup based off of your question. Here's an example of the hierarchy from what I could gather in your post:
public_html/ (all WP install files here)
public_html/admin/ (here I created a new folder similar to your question)
public_html/admin/index.php (test file - just echos a line of text)
public_html/admin/.htaccess (currently blank)
So my .htaccess within the new subdir that's spawned off of the WP root is blank. I'm not sure what kind of auth things would/should be in there. If I access "website/admin/" - the test line echos just fine. I don't see any 404s.
Could you maybe provide a little more detail so I can try to better replicate the issue you're seeing?
Found the solution for my problem elsewhere. Editing the root .htaccess (for wordpress) to match the one below should fix anyone who also encounters this issue:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/NameOf_Directory_ToAllow/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/NameOf_AdditionalDirectory_ToAllow/(.*)$ [OR]
RewriteRule ^.*$ - [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

404 due to WordPress mod_rewrite rule?

Client added a WordPress install to their document root directory. Afterwards one non-WordPress directory is giving a 404.
In a browser you can access /foo/facebook/index.php with no issues but you get the WordPress 404 page if you try to access /foo_admin/index.php. Wordpress is in / (not pictured here due to clutter).
Here is the entire .htaccess for the doc root directory:
# 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
EDIT:
Just realized a basic auth .htaccess in /gcb_admin is interfering somehow. Have now tried adding RewriteEngine off both before and after the basic auth directives but this changes nothing. Removing basic auth directives allows access to file...
AuthUserFile /home/foof/.htpasswd
AuthName "FOO Admin"
AuthType Basic
<Limit GET>
require valid-user
</Limit>
RewriteEngine off
How do I correct this?
Try this solution - essentially, it just turns off the rewrite engine in that specific directory:
http://wordpress.org/support/topic/exclude-directories-from-wp-rewrite
Add a .htaccess file to the directory that you want the Wordpress rewrite to ignore, with this code:
RewriteEngine off
Or, try changing the last line you have to:
RewriteRule ./ /index.php [L]

wordpress 500 - Internal server error

I installed the wordpress 2.9.2 a few days ago and it works correctly. today , i want to use permlink feature of wordpress.
I know , must modify my .htaccess file on my site root. but on my sub-domain root there is no any .htaccess file . so i create my .htacess file with follow content on sub-domain root (near index.php file):
<files .htaccess>
order allow,deny
deny from all
</files>
ServerSignature Off
<files wp-config.php>
order allow,deny
deny from all
</files>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Options All -Indexes
AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php
But after save it , i missed my blog . And i get follow error :
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
after this i remove the .htaccess file , but this was not correct.
What i can do for it?
Cheers
I'm not sure what your other settings are there, but your rewrite block is correct. Try removing the rest of the contents of the file all together and see what happens. It may just be that you have more than you even need. Here is the entirety of my .htaccess for one of my WordPress installs with permalinks working correctly.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
- EDIT -
Also, that .htaccess is from a root domain that has sub-domains working accordingly without additional files or modification to the .htaccess.
Seems like a .htaccess file does not exist by default. But when you explicitly change the permalink structure by going to Settings->Permalinks in the WP admin area, a .htaccess file is automatically deleted. So, you may try to delete your current .htaccess file and then enable permalikns from admin area and .htaccess file will be automatically generated. First, my Wp install had no .htaccess file but when I altered the Permalink structure, here's what I got in my .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I changed the .htaccess file with follow Content:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
But nothing happens and we have error again.
The amazing thing is: I removed the file, but the error is still there.

Resources