views:

78

answers:

1

I would like to add a rewrite Condition in my htaccess that would be true if calling a php file returns "true" or false otherwise. I' am using the -U switch in my RewriteCond to run a subrequest and if the condition is not satisfied, the PHP script returns a 404 error, which triggers the rewriteCond.

My goal is to run a URL shortening service in parallel with a PHP website.

Here is my current .htaccess

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond /smallurl/%{REQUEST_URI} !-U
RewriteRule (.*) index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) smallurl/$1 [L]

What is the best practice to achieve something like this? Recomendations, things I should be aware of? Is there a way to avoid the subrequest, or at least speed it up?

Thank you

A: 

You can use a RewriteMap to pass the REQUEST_URI to a php file, which returns the result - I think this would work with RewriteCond, although you might find it works better as a standard RewriteRule

The spec is at http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteMap

Basically, your php file needs to read from php://stdin and output the result to stdout

Sorry I can't be more helpful, it's not something I've done in a long, long time!

adam
Ok, thanks, I'll definitely try that. I might not even use a php file to return the result, but a simple shell script or command maybe, althgough then it's less platform independent...Thanks for the answer anyway
jfoucher