Skip to content
Advertisement

htaccess returns 404 at WordPress in subdirectory (desktop ok, mobile 404)

I have a website made in WordPress, installed in a subdirectory (let’s call it “wp_dir”). I have followed the instructions in https://wordpress.org/support/article/giving-wordpress-its-own-directory/, specifically:

  • change the root htaccess file
  • change the root index.php file
  • change the wp_dir htaccess file

It works well, in desktop, but not in mobile. In desktop, the site is rendered well: when you type “example.com”, it renders the wordpress site well, from the wordpress installed in wp_dir folder, with SSL and everything. All menu links work well.

In mobile, instead, when you type “example.com”, the url changes to “example.com/wp_dir”, with SSL, and menu links are shown, but shows a 404 error. Links work.

I believe the problem is SSL related. I have also tried removing the [L] directives, in order to allow the instructions to continue being executed, but to no avail. Something is not working ok, or in the proper order, but I can’t find what.

The htaccess file is pretty messed up with many different instructions (SSL, non-www redirection, permissions to other subdirectories for management applications, block exploits, etc). The site was previously built in Joomla. Obviously I’ve done something wrong, but I can’t figure out what that is.

How can it work well when you access it in a desktop computer, and not in a mobile phone?

Here is the current htaccess in the root directory (without the mess):

JavaScript

And here is the htaccess in the WordPress subdirectory (“wp_dir”):

JavaScript

In case it’s useful to see the full htacess file (with the mess), here it is:

JavaScript

EDIT: Added headers

These are the headers obtained with two different browsers.

In Firefox, I get the 301, and url keeps at “http ://www.example.com”.

Response headers:

JavaScript

Request headers:

JavaScript

These are the headers in Chrome, where I get a 404 and url “https ://www.example.com/wp_dir/”:

General:

JavaScript

Response headers:

JavaScript

Request headers:

JavaScript

Advertisement

Answer

I think there might be a problem with your rewrite in the subdirectory. First I presume you want to keep the same link. If we look at the tutorial linked there is only need for one .htaccess in the root directory.

Since if a request is made anywhere on the site and if it’s not a direct file or directory the root htaccess file will redirect it to the subfolder.

Now, your second subfolder .htaccess file is actually pointing back to the root directory. If you want to have a .htaccess redirect in the subfolder you should add the rewrite base and the subfolder to the redirect.

JavaScript
  1. If you look at this Hostinger tutorial it suggests you shouldn’t use the RewriteEngine On condition twice. And this is a nice explanation of this “problem”.

But summery if you use RewriteEngine or RewriteBase multiple times the last entry wins and is used throughout the .htaccess file.

Now I don’t understand did you access https://example.com/wp_dir/ directly or were you redirected there? If it was direct access I think the .htaccess was wrong as I pointed out.

Or it may be the phone cache.

Edit: And also modify the first .htaccess file. I think one https rewrite rule is redundant and another incorrect.

JavaScript

File as I’d put it

JavaScript

I may be wrong.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement