$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>htaccess - fix 302 redirection error on https|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

htaccess - fix 302 redirection error on https

matteradmin9PV0评论

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

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far