set up 301 redirect within wp-content/uploads/ directory of a WP site to a new image URL

If this image does not exist then the request will be rewritten to the WordPress front-controller before your redirect occurs. Try the following instead using mod_rewrite at the top of the .htaccess file, before the # BEGIN WordPress code block: RewriteRule ^(wp-content/uploads/2021/09)/image-1\.png$ https://%{HTTP_HOST}/$1/image-2.png [R=302,L] The $1 backreference in the substitution string simply avoids having to … Read more

Use virtual pages point to one specific page

I actually found a rather easy way to achieve this: add_rewrite_rule( ‘city/([a-zA-Z]+)/?$’, ‘wp-content/plugins/csv-to-html/templates/csvtohtmlpage_core.php?city=$1’ ); Yes, I know I did not mention city/ in the beginning but I just wanted wanted to know how should I achieve this. If someone has better ideas. Please tell me! 🙂

htaccess rules not applied?

Your rules are in the wrong order. Your “Custom Redirect” needs to be at the top of the .htaccess file before the WordPress front-controller, ie. before the # BEGIN WordPress comment marker. By placing it after the WordPress code block it will only get processed for requests that map directly to files and directories (including … Read more

Override htacces rule only for specific directory

To effectively disable that condition for that one URL-path, you will need to add another rule immediately before the rule in question. ie. before the # Abuse Agent Blocking comment. For example: # Allow an empty User-Agent for requests that start “/wp-content/uploads/xmls” RewriteCond %{HTTP_USER_AGENT} ^$ RewriteRule ^wp-content/uploads/xmls – [S=1] # Abuse Agent Blocking RewriteCond %{HTTP_USER_AGENT} … Read more

How can i redirect one url to another url using .htaccess or add_rewrite_rule

I’m honestly struggling to comprehend this failure state – I believe I’ve reproduced the issue locally, and in my testing the RewriteRule directive hits but then WordPress processes the original input, resulting in a fairly catch-all attachment rewrite producing a query for a non-existent attachment. I may continue playing with it to try and figure … Read more

Why is my mod_rewrite not working?

First, your additional line comes too late. The rule before catches everything you want to match. Second, it doesn’t what you want. Your … RewriteRule /([0-9]+/?)$ /about/latest-news/$1 [NC,L] … matches requests like example.com//0000000000000000000/ or example.com/about/latest-news/2010/ (infinite loop!). The first argument for RewriteRule omits the starting /. To match year archives you need rather: RewriteRule ^(\d\d\d\d)/?$ … Read more