Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Apache redirect help
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
remix
l33t
l33t


Joined: 28 Apr 2004
Posts: 797
Location: hawaii

PostPosted: Fri Jan 15, 2010 5:52 am    Post subject: Apache redirect help Reply with quote

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.
_________________
help the needy
Back to top
View user's profile Send private message
msalerno
Veteran
Veteran


Joined: 17 Dec 2002
Posts: 1338
Location: Sweating in South Florida

PostPosted: Fri Jan 15, 2010 3:58 pm    Post subject: Reply with quote

Try something like this:

Code:
RewriteEngine on
RewriteCond %{REQUEST_URI} !-f
RewriteRule .+ http://assets.mydomain.com%{REQUEST_URI} [L,R,NE]
Back to top
View user's profile Send private message
remix
l33t
l33t


Joined: 28 Apr 2004
Posts: 797
Location: hawaii

PostPosted: Fri Jan 15, 2010 8:02 pm    Post subject: Reply with quote

msalerno wrote:
Try something like this:

Code:
RewriteEngine on
RewriteCond %{REQUEST_URI} !-f
RewriteRule .+ http://assets.mydomain.com%{REQUEST_URI} [L,R,NE]


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) ?
_________________
help the needy
Back to top
View user's profile Send private message
pianosaurus
l33t
l33t


Joined: 19 Apr 2004
Posts: 944
Location: Bash$

PostPosted: Fri Jan 15, 2010 11:32 pm    Post subject: Reply with quote

msalerno wrote:
Try something like this:

Code:
RewriteEngine on
RewriteCond %{REQUEST_URI} !-f
RewriteRule .+ http://assets.mydomain.com%{REQUEST_URI} [L,R,NE]


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

Try this:
Code:
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.
_________________
PKA Cuber
Please add [SOLVED] to the subject of your original post when you feel that your problem is resolved.
Adopt an unanswered post
Back to top
View user's profile Send private message
remix
l33t
l33t


Joined: 28 Apr 2004
Posts: 797
Location: hawaii

PostPosted: Sat Jan 16, 2010 2:54 am    Post subject: Reply with quote

Cuber wrote:
msalerno wrote:
Try something like this:

Code:
RewriteEngine on
RewriteCond %{REQUEST_URI} !-f
RewriteRule .+ http://assets.mydomain.com%{REQUEST_URI} [L,R,NE]


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

Try this:
Code:
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.



cool that works!

thanks man
_________________
help the needy
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum