PHP - Loading a different file if exists
<p>For a while I've had a website, that grew and grew for years into several hundred individual php files. About 2 years ago I made a mobile version of the same website. I decided to do this by copying only the main files, and adjusting the header and the footer for mobile friendly. The rest worked as expected; I'd say 50% compatibility at this point.
Some of the sub-directories I decided that instead of copying them I could do a link using <code>ln -s</code>. This has solved the remaining 45%.</p>

<p>Recently I ran into a troubling situation. One of the files inside of this sym-linked subdirectories needs to be drastically different for the mobile version and for the full website. For normal files I would just make a hard copy, and modify the contents, but for a file within a sym-linked directory this is impossible.</p>

<p>Has anyone run into this? How can I solve this?</p>

<p>Here is the file layout &amp; example:</p>

<pre><code>/var/www/domain.com/
/var/www/mobile.domain.com/

/var/www/mobile.domain.com/images -&gt; /var/www/domain.com/images
/var/www/mobile.domain.com/tools -&gt; /var/www/domain.com/tools
</code></pre>

<p>If I need to modify a file /tools/help/wizard/configure.php then I can't have a unique file JUST for that file</p>

<p>One approach that I thought of, but don't like is modifying the mobile <code>header</code> file to check something like:</p>

<pre><code>if (file_exists("/var/www/mobile.domain.com/_overwrite_/" . $requested_file)) {
    // ... include it instead of running the actual file
}
</code></pre>

<p>This seems like an ugly approach. Similar can be done with Apache directives (I don't know them, but I'm guessing it's ModRewrite)</p>
