How to fix too many redirects in wordpress?
- User
How to fix too many redirects in wordpress?
- Assistant
The "too many redirects" error in WordPress typically occurs when there is a misconfiguration in your WordPress site's settings, or a conflict between different settings. Here are some steps you can take to fix the issue:
Clear your browser's cache and cookies: Sometimes, the error is caused by a caching issue in your browser. Clearing your cache and cookies can often solve the problem.
Check your WordPress site URL and home URL: Make sure that the WordPress Address (URL) and Site Address (URL) fields in the General Settings page of your WordPress dashboard are correct. If you recently changed your domain name or moved your site to a new server, these settings may need to be updated.
Check your .htaccess file: Your .htaccess file controls the URL structure of your site, so any errors in this file can cause the "too many redirects" error. You can try temporarily renaming your .htaccess file to see if that resolves the issue. If it does, you can regenerate a new .htaccess file by going to Settings > Permalinks in your WordPress dashboard and saving your permalinks settings again.
- User
I saw this code should help, why?
define('FORCE_SSL_ADMIN', true);
if( strpos(_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false ) _SERVER['HTTPS'] = 'on'; else $_SERVER['HTTPS'] = 'off';
- Assistant
The code you provided is used to force the use of SSL (Secure Sockets Layer) for the WordPress admin area, which helps to improve security by encrypting the data transmitted between the user's browser and the server. The first line of code defines the constant FORCE_SSL_ADMIN and sets it to true, which forces SSL to be used when accessing the WordPress admin area. The second part of the code checks whether the HTTP_X_FORWARDED_PROTO header is present in the request and whether it contains the value https. If it does, it sets the HTTPS variable in the $_SERVER superglobal array to on, which tells WordPress to use SSL. If the HTTP_X_FORWARDED_PROTO header is not present or does not contain the value https, the HTTPS variable is set to off. Overall, this code helps to ensure that the WordPress admin area is accessed securely using SSL, which can help to prevent unauthorized access to sensitive data and improve the overall security of your WordPress site.
- User
Where would you put this code?
- Assistant
You can add the code you provided in your WordPress site's wp-config.php file, which is located in the root directory of your WordPress installation. Here's how you can add the code:
Log in to your WordPress site's hosting control panel or FTP client.
Navigate to the root directory of your WordPress installation where the wp-config.php file is located.
Open the wp-config.php file in a text editor.
Add the following lines of code to the bottom of the wp-config.php file, just before the closing PHP tag (?>):
CopiarEditardefine('FORCE_SSL_ADMIN', true);
if( strpos(_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false ) _SERVER['HTTPS'] = 'on'; else $_SERVER['HTTPS'] = 'off';
Save the changes to the wp-config.php file.
Once you have added this code to your wp-config.php file, it should force SSL to be used for your WordPress admin area.
- User
there is no ?> in wp-config. Should it be before /* That's all, stop editing! Happy publishing. */ Or after everything?
- Assistant
You're correct, there is no ?> at the end of the wp-config.php file in WordPress. It is actually recommended to omit the closing PHP tag to avoid any whitespace or blank lines being outputted at the end of the file, which can cause issues with certain plugins or themes. Therefore, you should add the code just before the comment /* That's all, stop editing! Happy publishing. *
- User
I also have in the wp_config: define( 'WP_HOME', 'http://tei.ma' ); define( 'WP_SITEURL', 'http://tei.ma' );
When I added
if( strpos(_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false ) _SERVER['HTTPS'] = 'on'; else $_SERVER['HTTPS'] = 'off';
It ended in an error of redirect too many times, what should I do?
- Assistant
The redirect too many times error occurs when there is a redirect loop on your site, which can happen when WordPress is set to use HTTPS but your site is still loading over HTTP, or when there is a conflict between your site's HTTPS settings and any existing WordPress redirects. In your case, the issue might be related to the conflicting settings between the WP_HOME and WP_SITEURL constants, and the code you added to force SSL for the WordPress admin area. To fix this issue, you can try updating the WP_HOME and WP_SITEURL constants to use HTTPS instead of HTTP, like this: CopiarEditardefine( 'WP_HOME', 'https://tei.ma' ); define( 'WP_SITEURL', 'https://tei.ma' );
This will ensure that your site's URL is set to use HTTPS and prevent any redirect loops. If that doesn't work, you can try removing the code you added to force SSL for the WordPress admin area and instead use a WordPress plugin to force SSL across your entire site. One popular plugin that can do this is "Really Simple SSL", which can automatically detect your site's SSL certificate and configure your site to use HTTPS. I hope this helps!
- User
When I switch to https with or without the SSL code, the admin area is not working
- Assistant
If your WordPress admin area is not working after switching to HTTPS, it could be due to a few different reasons. Here are some possible causes and solutions:
Mixed content errors: When you switch your site to HTTPS, all the resources on your site (such as images, scripts, and stylesheets) should also be loaded via HTTPS. If any resources are still being loaded via HTTP, this can cause mixed content errors and prevent the admin area from loading correctly. To fix this, you can try using a plugin like "Better Search Replace" to search and replace all instances of http:// with https:// in your WordPress database.
Incorrect HTTPS configuration: If your HTTPS configuration is not set up correctly, it can prevent the admin area from loading. Make sure that your SSL certificate is valid and installed correctly on your server, and that your HTTPS configuration is set up properly in your web server software (such as Apache or Nginx).
Plugin or theme conflicts: Sometimes, plugins or themes can conflict with HTTPS settings and cause issues with the admin area. Try deactivating any plugins or themes that you recently installed or updated to see if this fixes the issue.