0

I would like to write a rule to redirect that kind or URL :

https://www.mywebsite.com/blog/wp-content/uploads/2007/06/DSC_1690.jpg

TO

https://www.mywebsite.com/wp-content/uploads/2007/06/DSC_1690.jpg

without the blog directory but ONLY for /blog/wp-content, i don't want to remove the /blog enretirely, because there is the blog here. i just want to move the wp-content at the root folder.

for all files inside /blog/wp-content to /wp-content

i tried that rule but it doesn't work : RewriteRule ^blog/wp-content/(.*)$ wp-content/$1 [L,NC,R]

Thanks for your help

  • https://stackoverflow.com/questions/18973058/how-to-remove-folder-name-from-url-using-htaccess – nitsram Mar 19 '18 at 15:37
  • Possible duplicate of [how to remove folder name from url using htaccess](https://stackoverflow.com/questions/18973058/how-to-remove-folder-name-from-url-using-htaccess) – Nico Haase Mar 19 '18 at 15:49
  • i don't want to remove /blog for all URL but only for /blot/wp-content URL so i need to match /blog/wp-content and not /blog, that's my problem – Alain Finckenbein Mar 19 '18 at 15:51

1 Answers1

0

Try this :

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/blog/(wp-content/)(.+)\sHTTP.*$
RewriteRule ^blog/wp-content/(.*)$         /%1$1 [L,R=301]
RewriteRule ^wp-content/(.*)$ /blog/wp-content/$1 [L,NE]

With rules above , you will be able to hide /blog/wp-content from URI but still get the same path internally.

Clear browser cache then test

Mohammed Elhag
  • 4,272
  • 1
  • 10
  • 18
  • @AlainFinckenbein put it before wordpress rules – Mohammed Elhag Mar 19 '18 at 16:50
  • it works with rules before worpdress rules thanks a lot ! but without the rule RewriteRule ^wp-content/(.*)$ /blog/wp-content/$1 [L,NE] could you explain me please for what is that rule please ? – Alain Finckenbein Mar 19 '18 at 17:00
  • @AlainFinckenbein this is to redirect that request internally to same path , but if you already have new path , remove it , the way that i gave you using when someone need to hide part of uri and still getting from same path internally – Mohammed Elhag Mar 19 '18 at 17:05