htaccess: why does a policy only work when it is included in WordPress directives?

The following directive aims to block access to the thank you page. It appears under WordPress directives. It does not work as intended, since the page remains accessible and does not show a 403 error

RewriteCond %{THE_REQUEST} ^(.*)?thanks?(/)$ (NC)
RewriteRule ^(.*)$ - (F,L)

When the policy is included as part of WordPress policies, it works as intended.


RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - (L)
RewriteCond %{REQUEST_URI} ^(.*)?thanks?(/)$ (NC)
RewriteRule ^(.*)$ - (F,L)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php (L)

Why does the first policy block not work and why does it only work when it is part of WordPress policies?

Reorder parts of the URL path to collect the date using .htaccess redirects

old permanent link:

https://www.example.com/2019/cat/subcat/10/25/post-name/amp/

new permanent link:

https://www.example.com/2019/10/25/cat/subcat/post-name/amp/

How can I redirect the old format to the new one with htaccess?

WordPress logout issues when using HTACCESS authentication

I am putting off because I am desperate for any response.

I thought about asking this question here because I am using Htaccess authentication and it is causing a problem when a
The user logs off.

I am trying my luck in Woocommerce and setting up some test users, when a user logs off the "Auth" screen appears
instead of the usual WP login screen. Can anyone help me solve this problem? Below is what I have in
.htaccess

Error Document 401 default
# Protect wp-login

AuthUserFile /home/xxxxxxxx/public_html/.htpasswd
AuthName "Private access"
AuthType Basic
user xxx required
user xxx required

ip address: block the ip range using htaccess

I am looking for a good way to block a full IP range using htaccess.

The problem I have is that the block I need to ban is 100 large IP ranges. From the programmers perspective, it should be easily feasible, but I can't do it without adding 100 lines in my htaccess, and other techniques I tried didn't work.

The range of IP addresses that I need to block is for HUAWEI clouds: 159,138,100. * – 159,138,199. *

Sharp spots on the eyes that basically 159,138.1 are enough to block.

I tried the following without success:

Order Allow,Deny
Deny from 159.138.1
Allow from all

I also tried:

Order Allow,Deny
Deny from 159.138.1*
Allow from all

How can I block this iprange effectively using .htaccess?

What is the Cloudflare equivalent of these two .htaccess redirection rules?

Usually, I configure my sites to rewrite URLs in the following cases:

  1. All http traffic is redirected to https (and www), with a 301
  2. All non-www traffic is redirected to www (and https), with a 301

In .htaccess, the rewrite rules are as follows:

RewriteEngine on
RewriteCond %{http_host} ^example.com (NC)
RewriteRule ^(.*)$ https://www.example.com/$1 (L,R=301)

RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} (R=301,L)

Note that all redirects are achieved with a single jump. No www traffic goes to www Y Https and not https traffic goes to https Y www. How to achieve the same results in Cloudflare?

PS I am not sure if it is worth enabling the "Always use HTTPS" option in Cloudflare, since it does not use a 301 and anyway I have to write a separate rule for an https redirect rule with a 301.

.htaccess to nginx rewrite rules

I have converted some .htaccess rules to nginx rewrite rules but they don't work. I tried different variations and tried online converters, but nothing seems to work.

Access Rules

RewriteEngine On
RewriteBase /layout/themes/

RewriteCond %{REQUEST_FILENAME} -f (OR)
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - (L)

RewriteCond %{REQUEST_FILENAME} !-f (OR)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) bootstrap4/$1 (L)

Nginx Rewrite Rules

rewrite ^/layout/themes/(.*)$ /layout/themes/bootstrap4/$1 break;

Friendly url with 3 parameters with .htaccess

How about I am trying to pass this url, which has 3 pk parameters, tournament and league is the following:

http: // localhost / web / play / pk = 566539 & tournament = mlb & league = NN

And what I want is to make it look like this:

http: // localhost / web / play / 566539 / mlb / NN

In my file .htaccess I have the following configuration:

Options +FollowSymLinks
RewriteEngine on


#RewriteRule ^play/((0-9)+)$  play.php?pk=$1

RewriteRule ^play((^/)+)/((^/)+)/(d+)/?$ play.php?pk=$1&torneo=$2&liga=$3 (L)




RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^((a-z)+)/?$ $1.php (NC)

.htaccess to redirect the subdirectory to its own domain name

I have for example 2 domain names
gl.example that points to /public_html/ (which has a subfolder /public_html/tlf/)
Y tlf.example pointing to the subfolder /public_html/tlf/

How do I redirect so that
if users visit https://gl.example/tlf/example.php going to
https://tlf.example/example.php

I basically want everything underneath gl.example/tlf look like it's on tlf.example domain.

Which .htaccess should i edit? The one below public_html/ or the one below /public_html/tlf/? Would you like to make an infinite loop from https://tlf.example points to the same /tlf binder?

WordPress multisite htaccess redirect subsite to new subsite

I have been working on a new site on WordPress while keeping the previous site up and running using a multi-site WordPress solution.

Now I need to redirect the old subsite to the new one, keeping all pages / references of publications as they are.

so that anyone who clicks on a previous link, also known as old.sitename.com/my-old-post, is redirected to new.sitename.com/my-old-post using wildcards or similar.

I don't want to write a redirect for every existing page / post if it can be avoided.

Does anyone have a good way of doing this?

htaccess: redirection from www to no 301 does not work

I am redirecting 301 in cpanel www to non-www (bare domain) and the code generated by Cpanel redirect does nothing when www is set to non-www.

Server Type:
(Litespeed server, the domain has the "Encrypt" certificate).

  • The DNS setting is (does not point www to non-www as CNAME)
  • both point to the same IP
  • mydomain.dev – A record – 127.0.0.1
  • www.mydomain.dev – A record – 127.0.0.1

No www to www – it works

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.dev$
RewriteRule ^(.*)$ "https://www.mydomain.dev/$1" (R=301,L)

Www a no www – it doesn't work

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{HTTP_HOST} ^www.mydomain.dev$
RewriteRule ^(.*)$ "https://mydomain.dev/$1" (R=301,L)

Any ideas?