Try something like this instead:
<If "%{THE_REQUEST} !~ m#\s/wp-admin#">
Header add Content-Security-Policy "default-src 'self';"
Header add Content-Security-Policy "script-src 'self';"
</If>
This should set the two headers only when the requested URL does not start with /wp-admin
.
The check is against THE_REQUEST
(as opposed to REQUEST_URI
) since REQUEST_URI
changes when the URL is rewritten by the WordPress front-controller. THE_REQUEST
is the first line of the request headers (a string of the form GET /wp-admin/something HTTP/1.1
) and does not change when the request is rewritten.
Maybe it would be nice if a loggedin user is on the website that the lines also not be executed.
(I need to do it with htaccess.)
You can’t reliably do this with .htaccess
. In .htaccess
you can only determine whether the authentication cookie is set, not whether it is set correctly.
Related Posts:
- Improve wordpress security by hiding non public resources
- Does this .htaccess security setting really work?
- File and directory permissions
- Using “wordpress_logged_in” to restrict direct access to uploads folder in 2021
- WordPress URL/Folder ReWrite using Htaccess
- Which WordPress scripts need to be executable for a fresh installation?
- Blocking access to wp-login via htaccess not working
- Attach to wp-login.php and xmlrpc.php
- XMLRPC filtering through htaccess not working
- Restricting user login by IP address
- WordPress: Adding Security
- How do I test to ensure that my wp-config file is protected?
- WordPress not seeing .htaccess rules
- Disable directory browsing of uploads folder
- Strange behaviour of is_user_logged_in() and get_current_user_id()
- Selectively Disabling PHP via .htaccess in Root Directory
- Should I prevent access to .htaccess and wp-config.php files?
- Blocking wp-login in HTACCESS has also blocked password protected pages
- Basic Auth .htaccess on wp-login, but allow logout from woocommerce
- Using htaccess to prevent spam through wp-comments-post.php
- How can I create a private site that is inaccessible from the outside?
- Restrict Content for only Contributors via .htaccess
- Allowing access to certain WordPress created pages or posts with htaccess / htpasswd
- WordPress site hacked. Has .htaccess been hacked?
- htaccess https redirect from www to non-www
- .htaccess and 500 error, extra character added
- Place static HTML files in path below WordPress page
- htaccess rewrite for author query string when WP is in subfolder
- Why “Settings->Permalinks” creates .htaccess file on nginx server?
- .htaccess for wordpress inside another wordpress install
- Rewrite /?rest_route=/ link to /wp-json/ without changing default permalink structure in apache
- Globally force SSL on all pages
- Isolating WordPress to a subfolder
- Correct htaccess to display page while also passing in GET parameters
- What is the role of .htaccess file in WordPress?
- Block access to wp-admin
- How have I misconfigured basic auth for my wordpress site?
- WordPress trims off the forward slash when import
- WordPress best solution shared theme for consumers and businesses (two url’s one instaltion)
- Redirect main domain to subdirectory
- Remove special characters in a URL
- How do I edit the htaccess file to optimize my website?
- Should I add the IP of the server that hosts my sites to the list of authorized IPs in the wp-admin/.htaccess?
- Block only external access to wp-cron.php on OpenLiteSpeed
- Removing code added to htaccess with insert_with_markers
- Site searches by Python for non-existent assets
- WordPress 404 on Subdomain
- Can’t Access Subdirectory
- How to ignore folder in site root while accessing a URL
- HTTP sitewide, except for: wp-admin, and 2 custom directories
- WordPress installed in root, need second in subdirectory with different domain
- htaccess has broken my site
- What to write in the htaccess in order to detect browser language and point accordingly?
- Only Allow Front End Access
- .htacess rewrite condition: page to seconddomain/page
- Separate 404 page for WordPress in subfolder
- Weird behavior of Dashboard, must be core files
- Remove trailing slash after .html extension
- Need help rebuilding lost htaccess file
- I have a page using a pretty url and a mod_rewrite rule matching it. I expected it to give an error but it’s working. Why?
- How do I setup htaccess for 301 redirects, post Joomla to WordPress migration? [closed]
- How to rename index.php to home.php
- Hide a subdirectory on my website hosting
- Can’t access WP site over WiFi network
- Creating a copy of a website in a subdirectory, wp-admin redirect problem
- disable WordPress 404 for one specific page/folder to receive actual php errors
- Troll the hackers by redirecting them
- .htpasswd asking for authentication on home page
- WordPress login fail after .htaccess domain redirect
- Redirect to new domain with .htaccess [closed]
- I am new in word pres my font awesome is not allow
- Access sub-domain when root public_html is protected with .htaccess password
- Redirect https://www.subdomain.domain.com is not redirecting to subdomain.website.com [closed]
- htaccess redirect throws an error: PHP Catchable fatal error: Object of class WP_Error could not be converted to string
- Can’t access htaccess [closed]
- .htaccess redirect not properly working [ ?utm_source=]
- hide theme files for admin beneath root
- Why my WordPress Site Asking for HTTP Authentication?
- Iterating users while user iteration is suppressed
- htaccess redirects invalid request to home page not 404
- Deny php execution in /wp-includes – using .htaccess in /wp-includes VS root folder
- WordPress How to rewrite URL for custom pages
- Downloading zip or tar.gz inside WordPress installation?
- WordPress permalinks is wrong. It wants me to change my htaccess file. But then site crashes
- How to move wordpress website from hosting account to localhost
- Clicking PUBLISH Now Redirects to 404 PAGE NOT FOUND
- Unable to find ‘full-path’ to my 404.php file
- Use htaccess to redirect wordpress non-existent page to homepage
- WordPress RSS feed to external XML
- Does htaccess password keep search engines out?
- Need to edit htaccess while moving on WordPress
- block seacrh engines for all pages EXCEPT homepage
- Issue after changing permalink structure [duplicate]
- My WP site and password was hacked, what to do? [closed]
- rewrite rule on plugin activation
- Url redirection using htacess for my website
- htaccess – Server Subdirectory With Different Name Than URL Subdirectory
- WordPress redirection
- Home page returns 404
- Browser Caching .htaccess