Running WP in a subdirectory nginx, wp-admin too many redirects

Hi,

I’m running WordPress in a subdirectory with Local, i.e. http://local.dev/wordpress/ and it works fine unless I try and access the site via https. If I do, I get a too many redirects message whenever I try and access the front end or the wp-admin folder.

If I add remove_filter( 'template_redirect', 'redirect_canonical' ); to my functions.php I can see the front end, but none of the assets load as they are all requested via http:// and are blocked due to insecure content. The /wordpress/wp-admin/ or wp-login.php links still display the too many redirects error.

Does anyone know how I can fix this? I have a feeling its an nginx conf setting somewhere.

Thanks

4 Likes

Hi Patrick,

Did you update the siteurl and home options in wp_options?

As far as the insecure asset issue, you can easily fix this by clicking on the SSL tab for the site in Local and then clicking “Trust”.

Yep, I updated siteurl and home to https and I also defined them in the config file, so I’m not sure what’s wrong really.

define( 'WP_SITEURL', 'https://site.dev/wordpress' );
define( 'WP_HOME', 'https://site.dev' );

Hello!

I have the exact same problem with my subfolder WordPress installations, and so do my colleagues at my agency.

Just like Patrick, we can access the frontend only if the following filter is active:

remove_filter( 'template_redirect', 'redirect_canonical' );

This however does not work on the admin screens, which remain unaccessible with error “Too many redirect”.

My Site & Home URL options are set correctly => screenshot http://d.pr/i/Oxd2C.

It would not be too much of an issue, if it weren’t for the latest Chrome updates that shove HTTPS in your throat :sob:

Thanks!
Guido

2 Likes

Same problem here.
On macOS Sierra 10.12.6
Local V 2.0.8

Hello!
I encountered the same problem. I still prefer to installl WordPress in subfolders, because different apps often exist on the same domain. I’m on iMac, with your last version of Local.
Thank you!

Adriano

Hey all,

I was able to get this running by doing the following:

  1. Create a new site. Even though this worked on both Preferred and Custom, I recommend using Custom for this setup that way you can tweak the nginx/Apache configs if needed.
  2. Browse to the site’s app/public folder
  3. Create a folder named wordpress
  4. Move all of the files into wordpress except for index.php.
  5. Copy index.php into wordpress
  6. Open up index.php in app/public and adjust the require() call to include wordpress so it looks something like require( dirname( __FILE__ ) . '/wordpress/wp-blog-header.php' );
  7. Use Adminer or Sequel Pro to edit the siteurl option in wp_options to include /wordpress
  8. Test the site! Make sure you hard refresh by pressing Cmd + Shift + R

I tested the site frontend, admin, login, and customizer with HTTPS and didn’t run into any problems.

4 Likes

Hi Clay!
Thank you for looking into that.

Alas, we already did what you suggested.
Actually, that happens to be the procedure suggested by WordPress in the Codex (method 2) in order to have your website in a subfolder of public_html.

However, I noticed that new SSL installations in Local have the following snippet in wp-config.php:

/* Inserted by Local by Flywheel. See: http://codex.wordpress.org/Administration_Over_SSL#Using_a_Reverse_Proxy */
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
	$_SERVER['HTTPS'] = 'on';
}

Including the snippet in the wp-config.php of my existing WordPress installation made it work again!

I suspect that Local inserts the snippet automatically when the certificate is trusted; I guess somehow the insertion didn’t work on my wp-config.php.

Thank you for your help!
Best wishes,
Guido

4 Likes

That did the trick for me coccoinomane! Nice one

2 Likes

If anyone is trying to run your site from a custom directory, setting up a site as Custom is they key to getting access to the nginx conf files.

1 Like