htaccess - fix 302 redirection error on https

admin2025-06-02  1

I have a problem with my wordpress fresh installation. I'm using the .htaccess to redirect all my traffic on https, but every time I see a 302 error page. How I can fix this?

here is the .htaccess file code

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

Options All -Indexes
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

I have a problem with my wordpress fresh installation. I'm using the .htaccess to redirect all my traffic on https, but every time I see a 302 error page. How I can fix this?

here is the .htaccess file code

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

Options All -Indexes
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
Share Improve this question asked Mar 1, 2019 at 19:08 ZWPDevZWPDev 1162 silver badges16 bronze badges 2
  • Ensure your site's home URL is https - this can be found in the wp_options table. If your site is multisite, check the site's site_url as well. – phatskat Commented Mar 1, 2019 at 19:11
  • "I see a 302 error page" - What do you mean by this? Is the browser reporting a redirect loop? – MrWhite Commented Mar 1, 2019 at 21:43
Add a comment  | 

1 Answer 1

Reset to default 1

First, you should not customize anything between # BEGIN WordPress and # END WordPress, it's just not a good practice. You should add your own rules above WP rules. And you should also make use of some flags, like "L".

# BEGIN Custom
<IfModule mod_rewrite.c>
Options All -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]
</IfModule>

# END Custom

# 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

Also, instead of defining WP site URL through admin you should define it using constants in wp-config.php. Here is a snippet you could make use of:

$protocol = ! empty( $_SERVER['HTTPS'] ) ? 'https://' : 'http://';

define( 'WP_HOME', $protocol . 'yoursite' );
define( 'WP_SITEURL', WP_HOME );

For more info: https://codex.wordpress/Changing_The_Site_URL

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748849565a314237.html

最新回复(0)