ekclone
ekclone

Reputation: 1092

.htaccess how to redirect the contents of a subdirectory to a directory

how can i achieve this If I want to redirect content from www.mysite.com/subdirectory/image.jpg to www.myothersite.com/image.jpg

but my current .htaccess redirects the content like this www.myothersite.com/subdirectory/image.jpg

RewriteEngine On    
RewriteRule \.(css|js|webp)$ http://myothersite.com%{REQUEST_URI} [NC,R=301,L]

Upvotes: 0

Views: 52

Answers (1)

anubhava
anubhava

Reputation: 785146

You can use this rule inside /subdirectory/.htaccess:

RewriteEngine On

RewriteRule ^.+\.(css|js|webp|jpe?g)$ http://myothersite.com/$0 [NC,R=301,NE,L]

%{REQUEST_URI} represents full URI but $0 here will have URI part after subdirectory/

Upvotes: 1

Related Questions