Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>While all what @Corey Henderson said makes absolutely perfect sense .. it is not 100% matches the reality.</p> <p>Have only these 2 rules in your .htaccess (I know, this is a bit stupid example, but you may run into the same effect eventually when doing complex rewrites):</p> <pre><code>RewriteEngine On RewriteRule (.*) /index.php?u=$1 [L] </code></pre> <p>You would think -- redirect ALL requests to <code>index.php</code>. Flag <code>[L]</code> is set so nothing to worry. Well -- apparently it is something to worry about, as after seeing [L] flag mod_rewrite goes to the next iteration (entering into a loop). Because we have rule that will <strong>always</strong> executed, we will have endless loop (well, there is setting in Apache config that controls it -- by default it is maximum 10 iterations). If limit is exceeded then you will see 500 Server Error message and this line in Apache's error.log: <em>"Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace."</em></p> <p>The rewrite will stop if:</p> <ol> <li>No more rules to process</li> <li>External Redirect <code>[R=301]</code></li> <li>Explicit "nothing to rewrite" command is given (second parameter of <code>RewriteRule</code> -- destination should be <code>-</code>.</li> <li>When rewriting to exactly the same URL as on beginning of iteration.</li> <li>Already mentioned "Request exceeded the limit of xx internal redirects".</li> </ol> <p>So yeah .. the faster rewrite iteration will be interrupted (rule is on the top) the better it is.</p> <p>When ordering your rules (when you have quite a few of them, not just 1-2-3) you may consider this logic (which rules goes on top):</p> <ol> <li>Rules for files/folders that you do not want to touch AT ALL, under any circumstances (process request as is, regardless of domain/protocol)</li> <li>Rules that do change domain (redirecting to <code>www.</code> for example) or protocol (forcing HTTPS) -- the quicker you do this the better it is (as if you do it too late it may already change URL from "nice" to real).</li> <li>Other important rules that may affect existing files/folders</li> <li>(Consider having this) "nothing to rewrite" for existing files/folders (see below, kind of #1 but for all existing resources)</li> <li>Other rules</li> <li>Catch all rule.</li> </ol> <p>On vast majority of sites where rewriting URLs is in place you will not have more that 5-6 rules (default .htaccess files for most PHP frameworks I have seen + some products like WordPress have just "catch all" (if file/folder does not exist then rewrite request to index.php)).</p> <p>Every website will have their own logic which makes the above list just a general recommendation, nothing more.</p> <hr> <pre><code># Do not do anything for already existing files RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule .+ - [L] </code></pre> <p><strong>My main point here is:</strong> If you have quite a few rules, consider inserting this kind of "nothing to rewrite" somewhere there to stop the iteration completely.</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. 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