Austin Biggs
Austin Biggs

Reputation: 177

.htaccess rewrite image urls

I'm trying to figure out how to redirect all image urls like this:

https://example.com/images/FILE.PNG

to this:

https://example.com/old-site/images/FILE.PNG

Is there an easy way to do this with .htaccess? I've looked around, but couldn't find a post anywhere with a similar scenario of adding a sub directory and don't understand htaccess rules well enough to write it myself.

Any and All help is appreciated!

Upvotes: 0

Views: 4232

Answers (2)

NGPixel
NGPixel

Reputation: 390

Using URL Rewrite in .htaccess:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/?images/(.*)$ /old-site/images/$1 [R=301,L]

Upvotes: 2

anubhava
anubhava

Reputation: 784958

You can use this one-liner rule in your root .htaccess:

RedirectMatch 301 ^(/images/.+)$ /old-site/$1

Upvotes: 0

Related Questions