Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After some fiddling, this is the best I can come up with that works across servers without the need for multiple server conditions:</p> <pre><code>RewriteCond %{SCRIPT_FILENAME} ^(.+)\/index.php$ [NC] RewriteRule .* - [E=PATH:%1] RewriteCond %{QUERY_STRING} ^request=(.*) [NC] RewriteCond %{ENV:PATH}/cache/%1.html -f RewriteRule ^.+$ cache/%1.html [QSA,L] RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^.+$ index.php?request=$0 [QSA,L] </code></pre> <p>The first part gets the full path of the directory that the request comes from and saves it as an environmental variable. index.php is trimmed from the end.</p> <p>The second part gets the internal redirect that contains the actual loaded URL, checks to see a cached version of the HTML exists and if it does carries out an internal redirect to it.</p> <p>The third part takes a "search engine friendly URL" and does an internal redirect to index.php?request={URL}.</p> <p>So in short, you load the url:</p> <p><a href="http://domain.com/page/sub-page" rel="nofollow">http://domain.com/page/sub-page</a></p> <p>The third condition set redirect this to:</p> <p><a href="http://domain.com/index.php?request=page/sub-page" rel="nofollow">http://domain.com/index.php?request=page/sub-page</a></p> <p>Then the second set (with the env. var. set in the first rule) sees if ./cache/page/sub-page.html exists on the server; if it does, that page is then displayed to the browser.</p> <p>N.B. to anyone who may find this of use that the third condition set is not neccesary, you could do this with just two rules. I use the redirect to index.php?request=555 as part of my PHP handling.</p>
 

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