Home > Enterprise >  Url rewrite [.htaccess] convert
Url rewrite [.htaccess] convert

Time:12-15

i have a web.config of iis server and i need to convert the redirect to apache [.htaccess] I try to do this and I success to get this:

RewriteRule ^wp-content/uploads/. ?\.(jpe?g|png|gif|svg)$ https://XX/YY%{REQUEST_URI} [R=301,L]

I get redirect to "HTTPS/xx/yy/wp-content/uploads" but I need to get this path: "HTTPS/xx/yy/uploads" - same without wp-content. how can I do it? Thanks!

CodePudding user response:

You need a capturing group in the RewriteRule pattern that excludes the wp-content/ prefix and use this in the substitution string, instead of REQUEST_URI, which contains the entire URL-path.

For example:

RewriteRule ^wp-content/(uploads/. \.(jpe?g|png|gif|svg))$ https://XX/YY/$1 [R=301,L]

No need for the non-greedy quantifier in the middle (ie. . ?) - it is marginally more efficient without.

You will need to clear your browser cache before testing since the erroneous 301 (permanent) redirect will have been cached by the browser.

Test first with a 302 (temporary) redirect to avoid potential caching issues.

  • Related