|
|
|
|
||||||
| alt.apache.configuration Apache web server configuration issues. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi,
I'm trying to use mod_rewrite to redirect to an external site, but only if the request wont't return a 404. It seems like RewriteCond -U might work, but it's evaluating as true regardless of whether url returns a 404. I'd really appreciate it if someone could share a tip on how to get this working - it's driving me crazy! RewriteEngine On RewriteCond http://externalsite.com{REQUEST_URI} -U RewriteRule ^(.*) http://externalsite.com{REQUEST_URI} [L] Thanks! Dan |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 11 Feb, 12:02, "Dan" <dan.gottl...@gmail.com> wrote:
> Hi, > > I'm trying to use mod_rewrite to redirect to an external site, but > only if the request wont't return a 404. It seems like RewriteCond -U > might work, but it's evaluating as true regardless of whether url > returns a 404. I'd really appreciate it if someone could share a tip > on how to get this working - it's driving me crazy! > > RewriteEngine On > RewriteCond http://externalsite.com{REQUEST_URI} -U > RewriteRule ^(.*)http://externalsite.com{REQUEST_URI} [L] > > Thanks! > Dan RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(/.*) http://www.somewhere.com/$1 [R,L,QSA] might do the trick, the QSA is to append the query string if the original request had one. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On 11 Feb, 12:02, "Dan" <dan.gottl...@gmail.com> wrote:
> Hi, > > I'm trying to use mod_rewrite to redirect to an external site, but > only if the request wont't return a 404. It seems like RewriteCond -U > might work, but it's evaluating as true regardless of whether url > returns a 404. I'd really appreciate it if someone could share a tip > on how to get this working - it's driving me crazy! > > RewriteEngine On > RewriteCond http://externalsite.com{REQUEST_URI} -U > RewriteRule ^(.*)http://externalsite.com{REQUEST_URI} [L] > > Thanks! > Dan Ah I misunderstood, you mean only redirect if the external host wont return a 404. my understanding of the -U flag is that it determines whether a local URL exists or not, by performing subrequests, rather than remote one, however if you have hostname resolving switched off on the server this would certainly stop the server from seeing a remote URL, if you reference it by using a hostname. so if the -U works with remote URL's you would have to have apache use DNS to find the IP for the remote host, which slows things down slightly and can lead to security and other issues. why not use scripting for something like this. that would be easy to accomplish. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Hi,
Thanks for the reply! I suppose I could write a script that does a HEAD request and redirects if there isn't a 404, but I'm concerned about performance as this would have to be called on every incoming request (scripts are slow...). Also, if I do a redirect in the response object, wouldn't the URL in the address bar change? Dan On Feb 11, 8:04 am, "shimmyshack" <matt.fa...@gmail.com> wrote: > Ah I misunderstood, you mean only redirect if the external host wont > return a 404. > > my understanding of the -U flag is that it determines whether a local > URL exists or not, by performing subrequests, rather than remote one, > however if you have hostname resolving switched off on the server this > would certainly stop the server from seeing a remote URL, if you > reference it by using a hostname. so if the -U works with remote URL's > you would have to have apache use DNS to find the IP for the remote > host, which slows things down slightly and can lead to security and > other issues. > > why not use scripting for something like this. that would be easy to > accomplish. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On 11 Feb, 13:47, "Dan" <dan.gottl...@gmail.com> wrote:
> Hi, > > Thanks for the reply! I suppose I could write a script that does a > HEAD request and redirects if there isn't a 404, but I'm concerned > about performance as this would have to be called on every incoming > request (scripts are slow...). Also, if I do a redirect in the > response object, wouldn't the URL in the address bar change? > > Dan > > On Feb 11, 8:04 am, "shimmyshack" <matt.fa...@gmail.com> wrote: > > > Ah I misunderstood, you mean only redirect if the external host wont > > return a 404. > > > my understanding of the -U flag is that it determines whether a local > > URL exists or not, by performing subrequests, rather than remote one, > > however if you have hostname resolving switched off on the server this > > would certainly stop the server from seeing a remote URL, if you > > reference it by using a hostname. so if the -U works with remote URL's > > you would have to have apache use DNS to find the IP for the remote > > host, which slows things down slightly and can lead to security and > > other issues. > > > why not use scripting for something like this. that would be easy to > > accomplish. I am interested in the problem you have, as you appear to want to redirect to an external site, but dont know before hand whether the external site can service the request you are asking of it. Do you own the remote site, or administer it, can you not simple grab a database of the remote host, and store it locally. (I understand this might not be possible) A redirect to an external site is just a header sent to the browser which tells it that the resource is located elsewhere, the client must then perform a DNS lookup to see where the server is, and then perform the request itself, this results in the URL changing as you mention. If you want to be able to return content on behalf of the site you are "redirecting to" then you must either user mod_proxy - which goes and retrieves the URL and alters some headers to make it seem to the client that the resource was located on your server; or write a script that performs the request on the behalf of your client, sending back the data to the client as if the resource was located on your site. mod_proxy is powerful and would probably be easier to implement. However a small php script would be super fast - actually faster than sending a request to your client and having them do the lookup and request and receive the data, probably because the web server you are running the script on has access to a dns server on the lan, and has super fast connectivity. I would be inclined to serve the data using a small php script myself, the performance overhead would be very small, unless you are doing this many times, in which case you might like to use a caching mechanism, and cache the DNS using php's cURL library to perform the request to the IP in question. mod_proxy has ProxyErrorOverride On which deals with 404's, the local 404 error script you would send the client to if there was a 404 from the remote server would be a default, or some script that could send back appropriate content. ErrorDocument 404 /static_404.html or ErrorDocument 404 /script/notfound.php or of course you can use mod_rewrite as you were doing to redirect in the case of a remote 404 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
Thanks for the thoughts - let me give you a little more background. I
have three servers: a web server running apache, an image rendering server, and amazon's s3 storage service (which hosts the rendered images). If a user requests an image that already has been rendered, I want to redirect to the amazon hosting service to serve the image. If a user requests an image that doesn't exist yet, I want to show a "coming soon" image on the 404. Then, the web server periodically greps the logs and send the images that need to be generated to the imaging server's queue which generates them and posts them to the amazon hosting service. The challenge is that I can't customize the 404 page from amazon, so I have to check if they've got the image before sending the user there. >From what you've written, I'll probably end up having to use a php script, but I'd rather avoid it as it would have to be called on every request (even if the client lookup is slower, at least it takes the load off of my server). Thanks, Dan > I am interested in the problem you have, as you appear to want to > redirect to an external site, but dont know before hand whether the > external site can service the request you are asking of it. Do you own > the remote site, or administer it, can you not simple grab a database > of the remote host, and store it locally. (I understand this might not > be possible) > A redirect to an external site is just a header sent to the browser > which tells it that the resource is located elsewhere, the client must > then perform a DNS lookup to see where the server is, and then perform > the request itself, this results in the URL changing as you mention. > If you want to be able to return content on behalf of the site you are > "redirecting to" then you must either user mod_proxy - which goes and > retrieves the URL and alters some headers to make it seem to the > client that the resource was located on your server; or write a script > that performs the request on the behalf of your client, sending back > the data to the client as if the resource was located on your site. > mod_proxy is powerful and would probably be easier to implement. > However a small php script would be super fast - actually faster than > sending a request to your client and having them do the lookup and > request and receive the data, probably because the web server you are > running the script on has access to a dns server on the lan, and has > super fast connectivity. > I would be inclined to serve the data using a small php script myself, > the performance overhead would be very small, unless you are doing > this many times, in which case you might like to > use a caching mechanism, and cache the DNS using php's cURL library to > perform the request to the IP in question. > mod_proxy has ProxyErrorOverride On which deals with 404's, the local > 404 error script you would send the client to if there was a 404 from > the remote server would be a default, or some script that could send > back appropriate content. > ErrorDocument 404 /static_404.html > or > ErrorDocument 404 /script/notfound.php > > or of course you can use mod_rewrite as you were doing to redirect in > the case of a remote 404 |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
On 11 Feb, 21:55, "Dan" <dan.gottl...@gmail.com> wrote:
> Thanks for the thoughts - let me give you a little more background. I > have three servers: a web server running apache, an image rendering > server, and amazon's s3 storage service (which hosts the rendered > images). > > If a user requests an image that already has been rendered, I want to > redirect to the amazon hosting service to serve the image. If a user > requests an image that doesn't exist yet, I want to show a "coming > soon" image on the 404. Then, the web server periodically greps the > logs and send the images that need to be generated to the imaging > server's queue which generates them and posts them to the amazon > hosting service. > > The challenge is that I can't customize the 404 page from amazon, so I > have to check if they've got the image before sending the user there.>From what you've written, I'll probably end up having to use a php > > script, but I'd rather avoid it as it would have to be called on every > request (even if the client lookup is slower, at least it takes the > load off of my server). > > Thanks, > Dan > > > I am interested in the problem you have, as you appear to want to > > redirect to an external site, but dont know before hand whether the > > external site can service the request you are asking of it. Do you own > > the remote site, or administer it, can you not simple grab a database > > of the remote host, and store it locally. (I understand this might not > > be possible) > > A redirect to an external site is just a header sent to the browser > > which tells it that the resource is located elsewhere, the client must > > then perform a DNS lookup to see where the server is, and then perform > > the request itself, this results in the URL changing as you mention. > > If you want to be able to return content on behalf of the site you are > > "redirecting to" then you must either user mod_proxy - which goes and > > retrieves the URL and alters some headers to make it seem to the > > client that the resource was located on your server; or write a script > > that performs the request on the behalf of your client, sending back > > the data to the client as if the resource was located on your site. > > mod_proxy is powerful and would probably be easier to implement. > > However a small php script would be super fast - actually faster than > > sending a request to your client and having them do the lookup and > > request and receive the data, probably because the web server you are > > running the script on has access to a dns server on the lan, and has > > super fast connectivity. > > I would be inclined to serve the data using a small php script myself, > > the performance overhead would be very small, unless you are doing > > this many times, in which case you might like to > > use a caching mechanism, and cache the DNS using php's cURL library to > > perform the request to the IP in question. > > mod_proxy has ProxyErrorOverride On which deals with 404's, the local > > 404 error script you would send the client to if there was a 404 from > > the remote server would be a default, or some script that could send > > back appropriate content. > > ErrorDocument 404 /static_404.html > > or > > ErrorDocument 404 /script/notfound.php > > > or of course you can use mod_rewrite as you were doing to redirect in > > the case of a remote 404 Hiya, firstly heres the cheapest (from your servers' points of view) but the least elegant and the most dodgy in terms of possible failures: <img src="http://www.google.co.uk/intl/fr_fr/images/logo.png" onerror="javascript:this.src='http://www.google.co.uk/intl/en_uk/ images/logo.gif'" /> where src is the image you want to be there, and onerror provides the notfound image url. No need for DNS lookups, or SS scripting, no exchange of headers between servers! But does require javascript, on FF it would be fast, however on IE there's a small timeout. In either browser the 404.html has to be downloaded by the user-agent before the onerror is triggered. Ha ha! Anyway more seriously, if PHP is running as an apache module the overhead should be negligible (IMHO) since the functionality would probably be handled by apache anyway. You have an interesting problem because although in theory you know ahead of time which images have (likely!) been processed, since the requests are all going via your web server, there's no way to quickly get at that info, even if you store it on the webserver, because the process of retrieving this info would be slow - via a local mysql connection not over tcp possibly not - so you are then stuck with exchange of info from the web server to AS3 and back, which will involve a DNS lookup - which can be dodgy on AS3 - as per the forum recently. If you cannot use mod_proxy on your webserver which has the functionality you are looking for, then I cant see another alternative to some sort of php / perl script that does a HEAD, however you could experiment, and use some kind of sqlite db to cache the images that will have been processed (using some kind of liklihood measure based on time and load of the image processing server, or a simple query once per hour on where it has got up to) you at least might find that an sqlite db is fast for even largish amounts of data compared to network latencies and other oddities. All sounds a bit over-engineered though doesnt it. I'm sure the answer you come up with will be elegant so if you feel like posting back, please do so!! You cant speculatively create the images can you, and cover all your bases before they are needed? |
|
![]() |
| Outils de la discussion | |
|
|