home projects speaker

How to permanently redirect static content to a subdomain with .htaccess

I wanted to move all my static files to a sub domain to comply with good standards and use a Content Delivery Network. I set up a sub domain and moved all the images, style sheets and javascript files to this subdomain. To play nice with the search engines and cached pages, I needed to set up a permanently redirect (301) so the content would not get lost

Put this in a .htaccess-file in your top www dir:

apacheconf
RewriteRule ^img/(.*)$ http://cdn.example.com/img/$1 [R=301] 
RewriteRule ^css/(.*)$ http://cdn.example.com/css/$1 [R=301]
RewriteRule ^js/(.*)$ http://cdn.example.com/js/$1 [R=301,L]

About the author

Hi! My name is Alexander, and I am a creative frontender, specializing in UX, accessibility, universal design, frontend-architecture, node and design systems. I am passionate with open source projects and love to dabble with new emerging technologies related to frontend. With over 24 years of frontend experience, I have earned the right to be called a veteran. I am a lover of life, technologist at heart. If I am not coding, I am cooking and I love whisky and cigars. Oh, and coffee, I LOVE coffee!

If you want to know more about me, here is some links you might want to check out: GitHub, Instagram, Twitter, LinkedIn, CodePen, Slides.com, npm,

Speaker

I am also an avid speaker on several topics! Check out some of the things I speak about, and contact me if you are interested in having me at your next event!