views:

25

answers:

2

Hi,

I'm writing a website that allows people to asses a web page's readability (Flesch-Kincaid Reading Ease, thank kind of thing).

Ideally I'd like the user to be able merely to preceed the target URL with mine (like many mirror sites do), and hey presto they can see the results.

I'm guessing it's got to be done with mod_rewrite, but I'm not sure how to write it, especially given that URLs may contain so much potential junk.

How would I say:

if request is mysite.com/anything-at-all ).

redirect to mysite.com/?site=anything-at-all

Except in cases where the request is for:

  • just for mysite.com/

  • The request is for mysite.com/ajaxresponse.php?target=something

  • Where the request is for about.php or loading.gif

Sadly everything that I have tried so far ends up in an redirect loop...

Many thanks,

Jack

+1  A: 

Edit your .htaccess to have:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.+)$ ?site=$1 [NC]

The + in the regex will take care of the index page being left as is. Edit otherwise as you deem necessary (make it a 302 permanent redirect, etc...)

For excluding the specific pages you should add a line:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(ajax\.php|whatever\.gif) - [L]
RewriteRule ^(.+)$ ?site=$1 [NC]
Yuval A
Ah, thank you! I also realised after I asked my question there were a couple of other specific URLs, an image and an AJAX response page that need excluding from the rule, is there an easy way to do this?Thank you
Jack Shepherd
A: 

Try this rule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} !(^|&)site=[^&]
RewriteRule .+ /?site=$0 [QSA]

The first condition is to exclude requests to existing files and the second is to avoid a redirect is there already is a site URL argument.

Gumbo
Man, that is PERFECT. Thank you!
Jack Shepherd