Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Preventing subfolder redirection |
|
Author |
|
sbs
Joined: 01 Mar 2010 Posts: 3
|
Posted: Mon 01 Mar '10 17:29 Post subject: Preventing subfolder redirection |
|
|
No question too simple? Well we'll see, this should be obvious but it's driving me crazy
Okay, so I have a htaccess redirect to my offsite blog running in the root of my domain using:
which works great but unfortunately it effects all my subfolders too (say example.com/junk), many of which I tend to use for easy image/document hosting, etc.
Is there any way to maintain the redirect in the root folder while preventing it from affecting specific folders (or even everything) below it?
Thought about meta redirects but it's a fairly dirty solution that I'd rather avoid, surely there must be a way to achieve this via htaccess?
Thanks to anyone who bothers reading this far. |
|
Back to top |
|
James Blond Moderator

Joined: 19 Jan 2006 Posts: 7407 Location: EU, Germany, Next to Hamburg
|
Posted: Tue 02 Mar '10 12:35 Post subject: |
|
|
Maybe you can redirect only php / html files. Than other types like your images are not affected.
e.g.
Code: |
RedirectMatch (.*)\.php$ http://www.anotherserver.com$1.php
RedirectMatch (.*)\.htm$ http://www.anotherserver.com$1.htm
|
|
|
Back to top |
|
sbs
Joined: 01 Mar 2010 Posts: 3
|
Posted: Tue 02 Mar '10 17:30 Post subject: |
|
|
Yeah, thanks that's basically what I ended up doing and as long as th defaults are .html/.htm/.php it should be fine for anything but really obtuse requests.
Appreciate your time and please, if anyone knows a way of preventing specific folders being affected I'd still love to hear it.
Cheers. |
|
Back to top |
|
James Blond Moderator

Joined: 19 Jan 2006 Posts: 7407 Location: EU, Germany, Next to Hamburg
|
Posted: Tue 02 Mar '10 18:25 Post subject: |
|
|
I thought a bit of it and with mod_rewrite it can work as you like.
Code: |
RewriteEngine On
RewriteRule (.*) http://www.anotherserver.com/%{REQUEST_URI}
#now disable it for some folder
RewriteCond %{REQUEST_URI} !^/junk [NC]
RewriteCond %{REQUEST_URI} !^/more_junk [NC]
|
|
|
Back to top |
|
black_harry
Joined: 22 Feb 2010 Posts: 15 Location: Germany, Stuttgart
|
Posted: Thu 04 Mar '10 22:08 Post subject: |
|
|
I found something in the Linux-Mag with regular expressions.
This works since Apache2.2:
google for "Ten Things You Didn't Know Apache (2.2) Could Do"
2nd page in the linux-magazine.
Looking on your expectations, 1 of the next 2 linkes should work (untested - you need only 1 of them !!!):
RedirectMatch ^/(?!images|icons|dir2|dir3/)(.*) http://dynamic.myhost.com/$1
RedirectMatch ^/(?!(?:images|icons|dir2|dir3)/)(.*) http://dynamic.myhost.com/$1
This redirects all, except the folders "images, icons, dir2, dir3"
If you work on windows, you should consider upper / lower case.
It looks ugly, but it works.
Example for images, icons:
RedirectMatch ^/(?![iI][mM][aA][gG][eE][sS]|[iI][cC][oO][nN][sS]/)(.*) http://dynamic.myhost.com/$1 |
|
Back to top |
|
sbs
Joined: 01 Mar 2010 Posts: 3
|
Posted: Thu 04 Mar '10 23:49 Post subject: |
|
|
Appreciate both your efforts.
Implemented JB's second idea earlier and it works if I change Junk from a Subfolder into a Subdomain (despite the folder itself remaining in exactly the same place).
Very odd but it seems to work (although I have some weird htaccess lag which I presumed was a cache thing but not, anyway that's a whole different issue).
Anyway, I'll be able to refer to both methods now should something go off in the future so very much appreciate both your efforts.
Cheers. |
|
Back to top |
|
|
|
|
|
|