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
- Why is this line of code Wrong in every WordPress .Htaccess security article?
- How to redirect all HTTP requests to HTTPS
- Default .htaccess file for WordPress?
- Which one does WordPress prioritize when it comes to php.ini, wp-config and .htaccess?
- Security and .htaccess
- htaccess disable WordPress rewrite rules for folder and its contents
- Admin-Ajax.php, SSL, Non-SSL
- How to Block Access to Standard Login Flow and Comment Flow
- How disable SSL redirect for specific URL?
- Which ways can be used to log in to WordPress?
- Why does the header set X-Robots-Tag apply to all pages?
- How to change “wp-admin” to something else without search-replacing the core?
- Error:406 not acceptable
- .htaccess Rewrite URL WordPress
- A plugin changes my .htaccess file and I can’t access httpd.conf as that’s a shared server
- How can I code my plugin to safely modify .htaccess?
- HTAccess stops me from accessing WordPress Dashboard links
- Create subdomain masking for each user in WordPress
- Redirect from different port to subdomain – htaccess
- .htaccess rewrite rule puzzle
- Allow logged in users who doesn’t belong to whitelisted ips
- Best way to redirect site in subdirectory to root?
- Missing slash after moving site to subfolder
- WildCard SSL with wordpress subdomain
- Install a Network under a mapped domain
- browser caching not disabled after disabling in .htaccess
- Transfer to HTTPS – mixed content on main page only [closed]
- Htaccess redirect after changing Language URL format
- Adding a SSL Certificate
- .htaccess Security Header Rules
- Modify the .htaccess file
- mod_rewrite loop, redirecting http to https on certain section of wordpress blog
- .htaccess in subdir gets ignored by WordPress’ own .htaccess in /
- sitemap contains weird links and does not contain my pages [closed]
- want to rewrite an URL in wordpress
- how to redirect 301 my old search query string to wordpress search query string?
- WordPress sites in subfolders
- Admin Panel Slowdown After SSL Verification
- WordPress category with 404 error
- How to block access to files without modifying .htaccess or ngnix config? [closed]
- Allow REST API over HTTP, the rest of the site forced to HTTPS
- Conflict with Force SSL and Rewrite Rules
- 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]
- 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
- How to rewrite 404 to home page using htaccess?
- Troll the hackers by redirecting them
- I am new in word pres my font awesome is not allow
- htaccess redirect throws an error: PHP Catchable fatal error: Object of class WP_Error could not be converted to string
- “Oops.” error on an html file directly uploaded to a subdirectory of my WordPress site
- WordPress permalinks confusion
- Sub domain URL slash / missing after domain and before Post & page slug
- Why my WordPress Site Asking for HTTP Authentication?
- I need to make one folder private
- htaccess redirects invalid request to home page not 404
- Deny php execution in /wp-includes – using .htaccess in /wp-includes VS root folder
- Force HTTPS for mapped domain pointing to wordpress domain
- WordPress How to rewrite URL for custom pages
- How can I restrict access, by IP, to the `wp-admin` folder/Dashboard?
- How to properly give WordPress its own directory
- 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
- Question with .htaccess and wp-login.php prevention
- WordPress RSS feed to external XML
- Does htaccess password keep search engines out?
- htaccess old php pages to new wordpress ones
- different CNAME to corresponding subfolders
- block seacrh engines for all pages EXCEPT homepage
- Problem with All in one WP Migration – only works the home page
- My WP site and password was hacked, what to do? [closed]
- htaccess – Server Subdirectory With Different Name Than URL Subdirectory
- How can I stop WordPress from catching URL’s for static pages that I save on my server
- .htaccess seems to be required but I can not find it
- cant access website thru www only works on direct xyz.com
- When accessing a wordpress blog, I want to force http when accessing wordpress via xmlrpc otherwise force https