Note that there are some explanatory texts on larger screens.

plurals
  1. PO-f is true for directory/file if directory.php is a file using %{SCRIPT_FILENAME}.php -f etc
    primarykey
    data
    text
    <p>I am trying to using mod_rewrite to send files to an engine.php file. I am running into an error when checking if a requested file exists with a .php extension. I will explain more after the code:</p> <pre><code>Options -Indexes +FollowSymlinks -MultiViews &lt;IfModule mod_rewrite.c&gt; RewriteEngine On # If the requested filename is not a file RewriteCond %{REQUEST_FILENAME} !-f # ... but the requested filename.php is a file RewriteCond %{REQUEST_FILENAME}.php -f # ... rewrite it to the engine RewriteRule ^(.*)$ engine.php?page=$1.php [QSA,L] # If the requested script filename is a directory RewriteCond %{SCRIPT_FILENAME} -d # ... and an index file exists RewriteCond %{SCRIPT_FILENAME}index.php -f # .. rewrite to the engine RewriteRule ^(.*)$ engine.php?page=$1index.php [QSA,L] # If the requested script filename is a directory RewriteCond %{SCRIPT_FILENAME} -d # ... and an index file exists RewriteCond %{SCRIPT_FILENAME}/index.php -f # .. rewrite to the engine RewriteRule ^(.*)$ engine.php?page=$1/index.php [QSA,L] # If the file is a PHP or HTML file RewriteCond %{SCRIPT_FILENAME} \.(php|html)$ # ... rewrite it to the engine RewriteRule ^(.*)$ engine.php?page=$1 [QSA,L] # If the script filename is not a file RewriteCond %{SCRIPT_FILENAME} !-f # ... rewrite it to the engine RewriteRule ^(.*)$ engine.php?page=$1 [QSA,L] &lt;/IfModule&gt; </code></pre> <p>I will state that I still have a way to go with mod_rewrite, so I hope that the above code isn't too bad and that my problem isn't some simple issue.<br> If the user requests "directory/file", but that file does not exist (e.g. the page could be stored in the database), it will work depending on a couple of variables: </p> <ul> <li>If the file "directory.php" exists, it will send "directory/file.php" to engine.php</li> <li>If the file "directory.php" exists, but the directory "directory" also exists, it will send "directory/file" to the engine (as wanted)</li> <li>If neither the file "directory.php" nor the directory "directory" exist, it will send "directory/file" to the engine (as wanted)</li> </ul> <p>As you can see, the error is when the file "directory.php" exists.<br> Hopefully this is a simple mistake I have made and that I can learn from. I guess we'll see!<br> <strong>EDIT</strong><br> A couple of examples to hopefully make it all a little clearer. It is assumed that these all start with "http://domain.com/". These are the <em>wanted</em> results:<br> Input: "directory"<br> Output: "directory/index.php"<br> Notes: "engine.php?page=directory/index.php" exists </p> <p>Input: "directory"<br> Output: "directory"<br> Notes: "engine.php?page=directory/index.php" does not exist </p> <p>Input: "directory/"<br> Output: "directory/indes.php"<br> Notes: "engine.php?page=directory/index.php" exists</p> <p>Input: "directory/"<br> Output: "directory/"<br> Notes: "engine.php?page=directory/index.php" does not exist </p> <p>Input: "file"<br> Output: "file.php"<br> Notes: "engine.php?page=file.php" exists </p> <p>Input: "file"<br> Output: "file"<br> Notes: "engine.php?page=file.php" does not exist</p>
    singulars
    1. This table or related slice is empty.
    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. 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