Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your rewrite rule looks almost ok.</p> <p>First make sure that your <code>.htaccess</code> file is in your document root (the same place as <code>index.php</code>) or it'll only affect the sub-folder it's in (and any sub-folders within that - recursively).</p> <p>Next make a slight change to your rule so it looks something like:</p> <pre><code>RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA] </code></pre> <p>At the moment you're just matching on <code>.</code> which is <strong>one</strong> instance of any character, you need at least <code>.*</code> to match any number of instances of any character.</p> <p>The <code>$_GET['path']</code> variable will contain the fake directory structure, so <code>/mvc/module/test</code> for instance, which you can then use in index.php to determine the <em>Controller</em> and actions you want to perform.</p> <p><br /> If you want the whole shebang installed in a sub-directory, such as <code>/mvc/</code> or <code>/framework/</code> the least complicated way to do it is to change the rewrite rule slightly to take that into account.</p> <pre><code>RewriteRule ^(.*)$ /mvc/index.php?path=$1 [NC,L,QSA] </code></pre> <p>And ensure that your <code>index.php</code> is in that folder whilst the <code>.htaccess</code> file is in the document root.</p> <p><br /> <strong>Alternative to <code>$_GET['path']</code></strong> (updated Feb '18)</p> <p>It's not actually necessary (nor even common now) to set the <em>path</em> as a <code>$_GET</code> variable, many frameworks will rely on <code>$_SERVER['REQUEST_URI']</code> to retrieve the same information - normally to determine which <em>Controller</em> to use - but the principle is exactly the same.</p> <p>This does simplify the <code>RewriteRule</code> slightly as you don't need to create the <em>path</em> parameter:</p> <pre><code>RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ /index.php [L,QSA] </code></pre> <p>The same rules about installing in a sub-directory still apply, e.g.</p> <pre><code>RewriteRule ^.*$ /mvc/index.php [L,QSA] </code></pre> <p><br /></p> <hr> <p><strong>The flags:</strong></p> <p><code>NC</code> = No Case (not case sensitive, not really necessary since there are no characters in the pattern)</p> <p><code>L</code> = Last (it'll stop rewriting at after this Rewrite so make sure it's the last thing in your list of rewrites)</p> <p><code>QSA</code> = Query String Apend, just in case you've got something like <code>?like=penguins</code> on the end which you want to keep and pass to index.php.</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.
 

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