# Apache redirect help

## remix

Hi,

what is the correct regex to match all files EXCEPT files ending with (.html|.htm|.css|.js|.php|.shtml|.txt|.xml|.csv)

or even better, all plain text files (non binary)

and then rewrite it to route to a different subdomain 

RewriteCond %{REQUEST_URI} FANCYREGEXHERE [NC]

RewriteRule .+ http://assets.mydomain.com%{REQUEST_URI}

and how do you put this in the global apache config that applies to every vhost so that it rewrite

http(s)://anysubdomain.primarydomain.tld/request

to

http(s)://assets.anysubdomain.primarydomain.tld/request

and finally, will the https be an issue?

thanks in advance.

----------

## msalerno

Try something like this:

```
RewriteEngine on

RewriteCond %{REQUEST_URI} !-f

RewriteRule .+ http://assets.mydomain.com%{REQUEST_URI} [L,R,NE]
```

----------

## remix

 *msalerno wrote:*   

> Try something like this:
> 
> ```
> RewriteEngine on
> 
> ...

 

this seems to be matching every request, including index http://mydomain.com/

how do i match anything that is not a static binary file (.jpg|.png|.gif|.mov|.flv|.swf) ?

----------

## pianosaurus

 *msalerno wrote:*   

> Try something like this:
> 
> ```
> RewriteEngine on
> 
> ...

 

This will match anything that is not a regular file (e.g. directories and symlinks).

Try this:

```
RewriteEngine on

RewriteRule !(\.jpg|\.png|\.gif|\.mov|\.flv|\.swf)$ http://assets.mydomain.com%{REQUEST_URI} [L,R]
```

This is not tested, and straight from memory. I may be a little off on the syntax, so read the documentation. Was there some particular reason you wanted to use a rewritecond?

I don't think there is an easy way to match on the MIME-type of the file, so you're stuck with file name patterns, I'm afraid.

You can add a rewritecond for %{HTTPS} ^on$ to redirect those to the https subdomain. See the documentation, and let me know if you need help with it.

----------

## remix

 *Cuber wrote:*   

>  *msalerno wrote:*   Try something like this:
> 
> ```
> RewriteEngine on
> 
> ...

 

cool that works!

thanks man

----------

