Using RedirectMatch to change host for certain file types

Using mod_rewrite to handle various content issues

Using RedirectMatch to change host for certain file types

Postby coda » Wed Sep 20, 2006 1:38 am

Below is what I currently use which works fine - certain file types are redirected to load off a different host server. But is there an easier way to write it, for example by combining all possible file types into (js|css|gif|jpg)... etc. ?

RewriteEngine On
RedirectMatch (.*)\.js$ http://www.newdomain.com$1.js
RedirectMatch (.*)\.css$ http://www.newdomain.com$1.css
RedirectMatch (.*)\.gif$ http://www.newdomain.com$1.gif
RedirectMatch (.*)\.jpg$ http://www.newdomain.com$1.jpg
RedirectMatch (.*)\.png$ http://www.newdomain.com$1.png
RedirectMatch (.*)\.swf$ http://www.newdomain.com$1.swf

--
Thanks.
coda
 
Posts: 6
Joined: Thu Oct 06, 2005 7:03 pm

Nevermind :)

Postby coda » Wed Sep 20, 2006 3:04 am

Think I solved it:

RewriteCond %{REQUEST_URI} (.*)\.(js|css|ico|gif|jpg|png|swf|exe)$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R,L]
coda
 
Posts: 6
Joined: Thu Oct 06, 2005 7:03 pm

Postby richardk » Wed Sep 20, 2006 7:28 am

It can be done with RedirectMatch:
Code: Select all
RedirectMatch 301 ^(.+)\.(js|css|ico|gif|jpg|png|swf|exe)$ http://www.newdomain.com$1.$2
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Content

Who is online

Users browsing this forum: No registered users and 12 guests

cron