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
You can use a
RewriteMapto pass theREQUEST_URIto a php file, which returns the result – I think this would work withRewriteCond, although you might find it works better as a standardRewriteRuleThe 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!