Synology Personal Websites htaccess results in 403 errors - wordpress

Synology Server with DSM 7.1.x (recently updated from DSM 6.x and downgrading back down to DSM 6.x is not recommended by Synology)
Webstation Enabled with HTTP back-end server: Apache HTTP Server 2.4 and PHP:
PHP 8.0
Personal Websites with these settings HTTP back-end server: Apache HTTP Server 2.4 and
PHP: PHP 7.4
Personal Websites use WordPress 5.x or 6.x which require a .htaccess file
Problem: Personal Website .htaccess in /homes/user/www folders causes the 403 error
Could delete .htaccess to stop 403 error but Personal Websites use WordPress which requires .htaccess - cannot just delete this file because some WordPress actions recreates the .htaccess file (such as changing Settings > Permalinks)
Newly created test user case: tmp
homes/tmp/www folder has "users" group with 775 permissions
homes/tmp/www/.htaccess has owner of "username" and group of "users" with 770 permissions
homes/tmp/www/wp-config.php has owner of "username" and group of "users" with 770 permissions
Even with permissions of 777 for ALL files in homes/tmp/www, the 403 error still exists with .htaccess
After deleting the .htaccess and creating/publishing a new page, viewing the new page results in a 404 error.
Default .htaccess lines
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /~username/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~username/index.php [L]
</IfModule>
Even if .htaccess has no lines of code at all, the 403 error exists. So just the existence of the .htaccess file regardless of content causes a 403 error.
Anyone have ideas to solve this problem?

Solution I stumbled upon:
Edit the httpd2x.conf for Apache2.x (whichever is chosen for Personal Websites)
Add the following code
UserDir www
<Directory "var/services/homes/*/www">
Options FollowSymLinks
AllowOverride All
</Directory>
I tried a bunch of stuff and I think the above was the trick.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /~username/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~username/index.php [L]
</IfModule>
It looks like you are using Apache per-user web directories? If that's the case then /~username is not a physical directory (it's an "alias" to your user directory) and your document root is effectively /~username/ (which really messes with root-relative URL-paths).
In which case, your .htaccess should be like this instead:
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
Note that I've removed the RewriteBase directive altogether.
However, if this is part of the WordPress code block (ie. inside # BEGIN WordPress ... # END WordPress) comment markers then WordPress is going to try and overwrite your changes unless you take additional steps to prevent this.

Related

Apache access to example.com/app from different root directory

For now, I have following directories:
WordPress directory is connected with example.com domain. I would like to access my Zend app by example.com/app URL, but it is in separated directory. I tried to add rewrite rule in htaccess file in WordPress directory, but server responds me with 400 error. I tried that without success:
RewriteRule ^app/(.*)$ ../zend_app/$1
And now I am not sure what to do. I think about some php file to include something from zend_app folder or to create symlink inside WordPress directory pointing to zend_app folder. What solution is better? Maybe there is another solution? I am using shared hosting, so possibilities are limited.
EDIT:
Here is my whole htaccess file from WordPress:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^app/(.*)$ zend_app/$1 [L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

no permission on wp_admin

I installed the latest version of wordpress in my hosting server. How ever I was not able to add any media. I checked the server space and I have still of huge free space. And then I try to access settings --> media , I got this error
You don't have permission to access /wp-admin/ on this server.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
I added the this into my .htaccess file but still no luck
# BEGIN WordPress
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
<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
Any ideas?
-Alan-
You must download Filezilla and put permissions 755 on every WP file inside your hosting. Also, if this don't work, try to remove all plugins, maybe some plugin is causing the problem.

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

.htaccess with wordpress and drupal site

In my root wordpress site running
I have the usual wp-content, wp-includes, wp-admin folders, but I also have my 'drupal' which is a drupal site
I have .htaccess file in both root and drupal directory
When i try to access any node of drupal website give page not found error of wordpress
Please a help me for that
Add RewriteRule ^drupal - [L] above the WP rules in the .htaccess that is located in the root.
I have seen this a lot with Cpanel and Fantastico.
https://www.drupal.org/forum/support/post-installation/2010-08-09/installing-wordpress-in-a-sub-directory-of-drupal
The topic is old but still relevant. Just wanted to share my solution to this problem.
In WP, go to Admin > Settings > Permalinks;
Scroll down to the
bottom; You should see this:
If your .htaccess file were writable, we could do this automatically, but it isn’t so these are the mod_rewrite rules you should have in your .htaccess file. Click in the field and press Ctrl+a to select all.
Add this to WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /YOURSUBDIR/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /YOURSUBDIR/index.php [L]
</IfModule>
Open your .htaccess in the Drupal root dir, and find this bit:
# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
Paste the WP Admin code underneath this, from "RewriteBase" to the end;
It should work now!
Make sure your WordPress permalinks are reset by hitting save ( the first URL here walks you through it
- https://www.cloudways.com/blog/fix-404-error-on-wordpress/
If that will not work try this.
See:
https://www.drupal.org/forum/support/installing-drupal/2007-08-02/the-requested-url-not-found-on-this-server
- I hope this is helpful cloudways.com will know the fix too.
Add this to WordPress
# 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
Ignoring Subfolders that exist in the DocumentRoot
With clean URL's enabled, when running other software applications in subfolders (subdirectories) of a Drupal root installation. your .htaccess file may rewrite those URL's to Drupal. This may be a particular problem for those with a Drupal installation in the root of their domain using Cpanel and Fantastico where Fantastico installs other software into subfolders. For example, phpSurveyor's admin interface as installed by Fantastico will not work with Drupal's default .htaccess settings. The URL for the admin interface is inaccessible and will return a "page not found" page in your Drupal site.
The trick is to modify .htaccess to ignore specific files/folders. So for example, if you have two folders, and in the root of your Drupal installation, modify your .htaccess file by inserting the following code directly after the "RewriteEngine on" directive, before the Drupal rewrites:
=========[ start of .htaccess snippet]==========
<IfModule mod_rewrite.c>
RewriteEngine on
#
# stuff to let through (ignore)
RewriteCond %{REQUEST_URI} "/folder1/" [OR]
RewriteCond %{REQUEST_URI} "/folder2/"
RewriteRule (.*) $1 [L]
#
====================[ end ]=====================
For each folder, you want to bypass, add a RewriteCond line, and end all but the final RewriteCond with [OR]. Note that the [L] in the rewrite rule tells it to stop there and bypass the rest of the rewrite rules.
Ignoring subfolders that are included via Apache Alias directives
As of 4.7, files and directories should be automatically allowed through in drupal's .htaccess setup. Thats what the !-f and !-d lines do.
However if you are working with Apache Alias or similar directives the file doesn't actually exist so drupal will take over like it should. The best way around it is to just add one more conditional that matches your location and make it skip it too. Thats what the ! means. Please see below:
RewriteCond %{REQUEST_URI} !^/yourDirectoryName
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
It essentially means Apply this rule if the REQUEST_URI doesn't start with /yourDirectoryName and the REQUEST_FILENAME isn't a real file or a real folder. Which is exactly what you want. There is an implied "AND" between the lines of that rule. The ! says "not like this".

Wordpress Intalled on a separate directory and .htaccess redirection

I've installed my wordpress site on a separate directory and followed all the steps described here and now I can access my site from my main domain. So, my Wordpress site is installed under: www.mysite.com/wp-site/ and now I can access my site under www.mysite.com, so all is great, exactly what I wanted. Wordpress is making this happen through an .htaccess file it creates that has the necessary code to make the redirection happen (SEE CODE BELOW).
My problem is that I have other directories on my site, such as www.mysite.com/another-directory-unrelated-to-wordpress/ that I cannot access anymore because I believe wordpress and the .htaccess file it created is redirecting everything to the root.
How can I avoid Wordpress from redirecting all my other subfolders and files? Thanks a ton for any ideas or help.
Here is the htaccess file code:
# 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
The way the WordPress .htaccess file works is if an existing file or directory is requested, it does not send the request through WordPress...that's what the !-f and !-d RewriteCond statements do.
So, there is something else going on with your site. Have you used Firebug or any other debugging tool to see what is happening with the request/response?
You could always enable mod_rewrite logging to see if that gives you a clue.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteLog "rewrite.log"
RewriteLogLevel 3
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
A RewriteLogLevel of 5 would give you the most information. Make sure to comment out or remove the RewriteLog* lines when you have figured out the issue.
UPDATE: Check this other SO answer to see if it resolves your issue

Resources