Moving wordpress to different url/server creates redirect loop

I'm trying to move my wordpress site in to different server and url. How ever i seem to have a persistent redirect loop problem. I think this is not a cache, cookie or plugin problem and I am suspecting incorrect/missing settings in .htaccess file might be the culprit. The server where i am doing the moving from, uses nginx web server and does not have .htaccess file. The hosting provider that i am trying to move into uses apache2 and does have following .htaccess file in html folder:

RewriteEngine On
 
RewriteCond %{HTTPS} off
 
RewriteCond %{HTTP:X-LB-Forwarded-Proto} !https 
 
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

AddHandler application/x-httpd-php73 .php

Can somebody interpret if this .htaccess file is causing the redirect loop and/or what should be in the .htaccess file when using wordpress?

Topic apache loop nginx htaccess redirect Wordpress

Category Web


As WordPress documentation says about .htaccess file:

WordPress uses this file to manipulate how Apache serves files from its root directory, and subdirectories thereof. Most notably, WP modifies this file to be able to handle pretty permalinks.

And a basic .htaccess file content will looks like this:

# BEGIN WordPress

RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

If that .htaccess that you says is inside your WordPress directory, you can rename it, and try to access you WP admin panel, go to your permalinks settings dashboard, hit without any change Save changes button at the bottom of that page, to regenerate a new .htaccess file on you installation directory automatically, with your current rewrite files rules, that matches with your website configuration.

Make sure to take a backup of your previous website installation if you made some changes to that file in the past, and copy the rules in the new generated files to preserve your old changes.


WordPress' standard .htaccess file contains:

# BEGIN WordPress

RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

It does look like your current .htaccess file is set up to redirect every request that comes in on any domain and any path. You can delete it and let WP generate its own, or use the standard one above.

When changing domains, you'll also need to make sure to run a migration script to update all instances of the old domain within your database. The WP CLI command wp search-replace is one fast way to do this; there are also plugins that will do the replacement, or your host may be able to run the migration for you. Also double-check that your wp-config.php file has the credentials for the new server rather than the old.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.