Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Mod-rewrite cannot serve files in sequence in this way. Instead it would proceed through the list of rules and if another rule after the first one matched <code>FileviewerID.php</code>, it would be subsequently rewritten. So while it is possible to use mod_rewrite to match multiple rules on a request, it won't perform a branching into multiple requests.</p> <p>Really, the proper way to handle this is in your PHP code rather than try to get the web server to do it for you.</p> <p>Following a successful write to your database in <code>FileviewerID.php</code>, call <code>header()</code> in PHP to redirect to <code>File.php</code>.</p> <pre><code>// Fileviewer.php // Write to database was successful, redirect to File.php... header("Location: http://example.com/File.php"); exit(); </code></pre> <h3>Update after comments:</h3> <p>To make this work for files other than <code>.php</code>, you can still use PHP to store in the database and handle the correct redirect, but you would need to retrieve more information from the redirect in Apache. You should capture the file extension as well as the number.</p> <pre><code># Capture both the number and the extension RewriteRule ^File-(\d+)\.([A-Za-z]+)$ FileviewerID.php?x=$1&amp;ext=$2 </code></pre> <p>In your PHP <code>FielviewerID.php</code>, process your database action and redirect using the extension as gathered from <code>$_GET['ext']</code>.</p> <pre><code>// FileviewerID.php: // Store file id in database from $_GET['x'] (hopefully using prepared statements) // Then redirect using the file extension from $_GET['ext'], which holds an alphabetic string like "php" or "js" // Verify that the extension is alphabetic // Consider also checking it against an array of acceptable file extensions for // more reliable redirects. if (preg_match('/^[a-z]+$/i', $_GET['ext'])) { header("Location: http://example.com/File.{$_GET['ext']}"); exit(); } else { // Redirect to some default location for an invalid extension } </code></pre>
 

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