Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Build a static mod_rewrite file based on the logic in redirect.php and deploy that to a .htaccess; then the clients won't even touch php.</p> <p>If you don't know all the variables ahead of time, you can still add them to the .htaccess file as they are generated the first time, essentially the values are generated on the fly, but cached thereafter. The first hit for a given route is slow, PHP builds the rewrite_rule and places it in the .htaccess file. Subsequent requests for said route don't touch the PHP. You'll have to come up w/ a purging method to remove invalid routes if those come up (maybe even dedicate an entire .htaccess file just for these type of routes and delete the entire thing periodically). You'll also need to employ a mutex with this approach.</p> <p>Here's a boilerplate function you could wrap with a mutex / error handling logic; it also supports the Location redirect as an option.</p> <pre><code>&lt;?php /** * Generate redirect, either in the form of a Location header * (sent directly to STDOUT) or an rewrite rule intended to be * placed in a .htaccess file. * * @param $sGameName key indicating the game name * @param $sReferrer string Additional value appended to result URL * @param $bLocationHeader boolean If true send Location header * * @return string|false If $bLocationHeader is false (default) the mod_rewrite rule is returned. * Return false if the gamename isn't part of the map */ function gen_redirect($sGameName, $sReferrer, $bLocationHeader=false) { // Establish the game name based URL map, // this would go in a static variable if gen_redirect was part of a class. static $aPaths; if($aPaths === null) $aPaths = array( 'gamename1' =&gt; 'http://affiliatelink.com/?a=11111&amp;c=222222&amp;s1=', 'gamename2' =&gt; 'http://affiliatelink.com/?a=11112&amp;c=222223&amp;s1=', 'gamename3' =&gt; 'http://affiliatelink.com/?a=11113&amp;c=222224&amp;s1=', ); // Bail if the game name is unknown (might want to do something // more substantial here, or as a result of this) if(!array_key_exists($sGameName, $aPaths)) return false; $sRedirectUrl = $aPaths[$sGameName] . $sReferrer; // Generate the redirect in the form of a Location header // and send it to STDOUT if($bLocationHeader === true) { header('Location: ' . $sRedirectUrl); return; } // Generate the redirect as a mod_rewrite rule return 'RewriteRule ^play/' . $sGameName . '$ ' . $sRedirectUrl . ' [QSA,L]'; } echo gen_redirect('gamename1', 'http://moxune.com') . PHP_EOL; echo gen_redirect('gamename2', 'http://moxune.com') . PHP_EOL; echo gen_redirect('gamename3', 'http://moxune.com') . PHP_EOL; </code></pre> <p>A run of the test script:</p> <pre><code>bash-3.2$ php htaccess-redirect-builder.php RewriteRule ^play/gamename1$ http://affiliatelink.com/?a=11111&amp;c=222222&amp;s1=http://moxune.com [QSA,L] RewriteRule ^play/gamename2$ http://affiliatelink.com/?a=11112&amp;c=222223&amp;s1=http://moxune.com [QSA,L] RewriteRule ^play/gamename3$ http://affiliatelink.com/?a=11113&amp;c=222224&amp;s1=http://moxune.com [QSA,L] </code></pre> <p>It looks like you'll need to accept one more inbound parameter to represent the referrer from the clients to pull it off though, essentially your generic rule would be:</p> <blockquote> <p>/play/[game-name]/[referrer-name] -> http://affiliatelink.com/?[fields-from-url-map]&amp;s1=[referrer-name]</p> </blockquote> <p>Also, if you're on Linux, I'm a fan of <a href="http://us.php.net/manual/en/ref.sem.php" rel="nofollow">sem_get &amp; friends</a> for a mutex implementation ;)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload