Redirect to https not working with .htaccess [closed]

You’ve put the code in the wrong place. The HTTP to HTTPS directives must go before the WordPress front-controller, otherwise it’s simply never going to get processed for anything other than direct file requests. Your custom directives should also be outside the # BEGIN WordPress block, otherwise WordPress itself is likely to override your directives … Read more

Does WP Have a Function To Generate .htaccess RewriteCond?

In short yes… ‘External’ Rewrite Rules If in add_rewrite_rule the rule is isn’t directed to index.php then the rule is treated as an ‘external’ rule (i.e. not to be processed by WordPress’ internal handing of rewrites) and instead written to the .htaccess file. I.e. if: add_rewrite_rule(‘^nutrition/([^/]*)/([^/]*)/?’,’somethingelse.php?p=12&food=$1 &variety=$2′,’top’); is used instead of add_rewrite_rule(‘^nutrition/([^/]*)/([^/]*)/?’,’index.php?p=12&food=$matches[1]&variety=$matches[2]’,’top’); Then the rule … Read more

Why should I password protect WP-Admin?

The protection from .htaccess is for the folder /wp-admin it’s not for the URL Open up your ftp programme (or download WordPress) and look inside /wp-admin By only allowing your IP access this folder you’re blocking a lot of possible exploit issues (as mentioned in comments below). I always prefer to login at mysite.com/wp-admin and … Read more

Redirect user if it’s not logged in

I wouldn’t use htaccess for that. What I would do is make a ‘download page’ template and use it to ‘serve’ the files. By doing that, I can do a check with is_user_logged_in() Codex and redirect with wp_login_url() Codex Just do: if ( is_user_logged_in() ) : //file link else : wp_login_url(); endif; I think it’s … Read more

Using “wordpress_logged_in” to restrict direct access to uploads folder in 2021

Check to see if a person is logged in: <IfModule mod_rewrite.c> RewriteCond %{REQUEST_FILENAME} (.*) RewriteCond %{HTTP_COOKIE} !wordpress_logged_in_([a-zA-Z0-9_]*) [NC] RewriteRule .* – [F,L] </IfModule> The same applies as it did 10 years ago. This code in .htaccess doesn’t have anything to do with how WordPress might be setting cookies. And this does not “check to see … Read more

$_POST empty on submit (same code, same form submits normally on local server)

The best way to deal with Form Posts in WordPress is to use a special endpoint, /wp-admin/admin-post.php. POST data can be messed up, both by the WP Query call, and by any redirects that happen. So you set up your form with this action: <form action=”<?= admin_url(‘admin-post.php’) ?>” method=”post”> <input type=”hidden” name=”action” value=”special_action”> <?php wp_nonce_field(‘special_action_nonce’, … Read more

What is the role of .htaccess file in WordPress?

The .htaccess file is not actually required for WordPress to “work”. However, it is required if you wish to create a more user-friendly URL structure (ie. anything other than “plain” permalinks, as Jack suggests). This is also why the default WordPress .htaccess file surrounds the directives in an <IfModule mod_rewrite.c> container. It “works” if “mod_rewrite” … Read more