I want to redirect every URLS that's www.example.com/wordpress/wp-content...
to www.example.com/wp-content...
If you want to keep the old media URLs (for these external apps) then you should internally rewrite the request, not externally "redirect" it. Redirecting will be slow (if the app actually follows the redirect) and potentially doubles the requests to your server.
The following would need to go near the top of the root .htaccess
file, before the existing WordPress code block.
# /.htaccess
# Rewrite old media URLs to new location
RewriteRule ^wordpress/(wp-content/.+\.(jpg|webp|gif))$ $1 [L]
The $1
backreference refers to the first captured group in the preceding RewriteRule
pattern. In other words, the part of the URL-path from wp-content/
onwards, including the filename. Ideally, you should be specific and match only the file-extensions you are interested in.
Alternatively, keep the /wordpress
subdirectory and in the /wordpress/.htaccess
file use the following instead:
# /wordpress/.htaccess
RewriteEngine On
# Rewrite old media URLs to new location
RewriteRule ^(wp-content/.+\.(jpg|webp|gif))$ /$1 [L]
Note the absence of the wordpress
subdirectory in the regex and the additional slash prefix on the substitution string (to rewrite to the root-directory).
In using the /wordpress/.htaccess
file it will completely override the mod_rewrite directives in the parent .htaccess
file.