Say I have a rewrite that needs to pass the url to a PHP function and retrieve a value in order to tell what the new destination should be? is there a way to do that?
Thanks.
UPDATE:
Thanks so far guys..I am still having trouble but i’ll show you my code:
.htaccess
#I got the file path by echoing DOCUMENT_ROOT and added the rest.
RewriteMap fixurl prg:/var/www/vhosts/mydomain.com/httpsdocs/domain_prototype/code_base/url_handler.php
RewriteEngine On
RewriteRule (.*) ${fixurl:$1} [PT]
PHP:
set_time_limit(0); # forever program!
$keyboard = fopen("php://stdin","r");
while (1) {
$line = trim(fgets($keyboard));
print "www.google.com\n"; # <-- just test to see if working.
}
However I am getting a 500 Internal Server Error I am not sure if there is an error in my .htaccess or in my PHP?
There is something called a RewriteMap.
You can call an executable script that will return the URL to rewrite to.
Check this article for more information and examples (in Perl, but are totally applicable to any other language):
http://www.onlamp.com/pub/a/apache/2005/04/28/apacheckbk.html
Summary of caveats:
This is the way to create the map
And now we can use it in a RewriteRule:
EDIT: About the Internal Server Error. The most probable cause is what Gumbo mentions, RewriteMap cannot be used in .htaccess, sadly. You can use it in a RewriteRule in .htaccess, but can only create it in server config or virtual host config. To be certain, check the error log.
So, the only PHP / .htaccess only solution would be to rewrite everything to a certain PHP program which does the checking and redirects using the Location header. Something like:
Then, in proxy.php