Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to RewriteRule if file exists elsewhere
    primarykey
    data
    text
    <p>I have been trying to accomplish the same as many frameworks do: having the request processed by a .php (namely, index.php), while keeping a <code>/application/public</code> folder which contains all the elements that should be shown in case they exist. For example:</p> <pre><code>folder /application/public total 28K 92897619 drwxr-xr-x 5 1001 1001 4.0K Jul 29 00:07 . 92897616 drwxr-xr-x 7 1001 1001 4.0K Jul 28 23:31 .. 92897754 -rw-r--r-- 1 1001 1001 15 Jul 29 00:07 .htaccess 92897733 drwxr-xr-x 2 1001 1001 4.0K Jul 28 23:31 images 92897620 -rw-r--r-- 1 1001 1001 696 Jul 28 23:58 index.php 92897625 drwxr-xr-x 2 1001 1001 4.0K Jul 28 23:31 javascript 92897734 drwxr-xr-x 2 1001 1001 4.0K Jul 28 23:31 stylesheets folder /: total 24K 92831996 drwxr-xr-x 4 1001 1001 4.0K Jul 29 02:44 . 91980897 drwxr-xr-x 5 0 0 4.0K Jul 6 00:30 .. 92831975 -rw-r--r-- 1 1001 1001 360 Jul 29 02:44 .htaccess 92897616 drwxr-xr-x 7 1001 1001 4.0K Jul 28 23:31 application 92832733 -rw-r--r-- 1 1001 1001 696 Jul 29 00:02 index.php 92897739 drwxr-xr-x 6 1001 1001 4.0K Jul 28 23:31 system </code></pre> <p>If there is a request for <code>example.com/images/a.jpg</code>, <code>/application/public/images/a.jpg</code> should be shown, as it exists. Otherwise, index.php would get <code>?uri=images/a.jpg</code> as query string.</p> <p>With this in mind, I wrote the following .htaccess (placed at /):</p> <pre><code>Options +FollowSymLinks +Indexes RewriteEngine on RewriteBase / RewriteCond %{DOCUMENT_ROOT}/application/public%{REQUEST_URI} -f RewriteCond %{DOCUMENT_ROOT}/application/public%{REQUEST_URI} -d RewriteRule ^(.*)?$ application/public/$1 [L] RewriteRule ^(.+)?$ index.php?uri=$1 [PT,QSA,L] </code></pre> <p>Still, requesting for anything existent at <code>/application/public</code> redirects the request to <code>index.php</code> (for example, <code>example.com/images/a.jpg</code> ends up being <code>example.com/index.php?uri=images/a.jpg</code>).</p> <p>Apache logs only show the following (when requesting <code>example.com/javascript/index.php</code>):</p> <blockquote> <p>File does not exist: /home/jbayardo/www/test/javascript</p> </blockquote> <p>This, as you can imagine, leaves me in the blank.</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. 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