WordPress指定页面强制HTTPS的.htaccess规则引发404问题求助
Looks like the issue comes from a couple of small but critical issues in your .htaccess rules—let's break this down and fix it step by step:
1. Syntax Error in Rewrite Flags
The first problem is the extra space after the comma in your RewriteRule flag: [R=302, L]. Mod_rewrite is strict about flag formatting, and that space causes the rule to be parsed incorrectly. This means your redirect might not be firing properly, or it's conflicting with WordPress's internal routing.
2. Imprecise URI Matching
Your original RewriteCond %{REQUEST_URI} membership works, but since your WordPress is installed in the /draw/ directory, adding a more specific match will prevent accidental redirects and ensure the rule targets exactly your membership pages.
Corrected .htaccess Code
Here's the fixed version of your file with explanations included:
RewriteEngine On # Redirect to HTTPS only for membership pages in the /draw/ directory RewriteCond %{HTTPS} off # Match any URI starting with /draw/membership (add [NC] for case-insensitive matching) RewriteCond %{REQUEST_URI} ^/draw/membership [NC] # Fixed flag format (no space after comma) RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L] # BEGIN WordPress <IfModule mod_rewrite.c> # We already enabled RewriteEngine at the top, so no need to enable it again RewriteBase /draw/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /draw/index.php [L] </IfModule> # END WordPress
Additional Tips
- If your membership pages have slugs that contain "membership" (e.g.,
/draw/membership-plansor/draw/premium-membership), replace the URI condition withRewriteCond %{REQUEST_URI} membership [NC]to match any occurrence of the word. - Use
R=302for testing to avoid caching issues, then switch toR=301once you confirm everything works. - After updating
.htaccess, go to your WordPress admin → Settings → Permalinks and click "Save Changes" without modifying anything. This flushes WordPress's rewrite rules and ensures it recognizes the HTTPS versions of your pages.
内容的提问来源于stack exchange,提问作者user2794858

