views:

103

answers:

1

i have a proxy script which writes very ugly long URL. the proxy script automaticaly rewrites all href links with long ugly URL,

mysite.com/proxy.php?url=somesite.com
mysite.com/proxy.php?url=somesite.com/somedir
mysite.com/proxy.php?url=somesite.com/somedir/somepage.php

to fix this i have done 2 things

  1. edit the proxy script so that all href links are rewritten as

    mysite.com/somesite.com
    
  2. added a rewrite rule in .htaccess so that short URLs now rewrite...

    mysite.com/somesite.com

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*)$ proxy.php?url=$1 [L,QSA]

the problem is that, whenever i click a link on a proxy loaded page, it seems to take a lot longer than before i did all this cosmetic work. is something wrong with my rewrite rule ?

+3  A: 

The test you've written does two file tests (if 'not-file' and 'not-dir') and if they are true, it will execute your RewriteRule. This test is done for every request. Even if the result would've otherwise only required a HTTP 304 (not modified) response or when the actual files are currently held in memory by Apache.

It's possible that this slows down your site significantly if it contains many (server/client cached) images or other resources. To prevent this, try to filter without the need to access your file system. Filter as much as possible by using a regular expression. The easiest way to do this is by changing the URI path part to something unique, for instance example.com/u=somesite.com or even example.com/p/somesite.com (p for proxy)).

Your tests will be much faster if all you need to do is a regular expression pattern match as opposed to two file-existence tests (example for example.com/p/somesite/etc/....):

RewriteCond %{REQUEST_URI} ^/p/
RewriteRule ....

Update: expanded a bit and added small example

PS: even if you do not want to change your current brief URI scheme, you can use this pattern temporarily to test whether it changes performance for the better.

Abel