Note that there are some explanatory texts on larger screens.

plurals
  1. PO.htaccess front controller mod rewrite trouble
    primarykey
    data
    text
    <p>I know this should be simple but I'm having a hard time writing the .htaccess rule for my front controller.</p> <p>The /themes/ folder contains all my css/js/images etc so I don't want them to pass though my controller</p> <p>The .htaccess file is in the root of the /myadminarea/ folder.</p> <p>The root of the site (below '/myadminarea' on '/' has NO .htacess file)</p> <p>Inside the front controller I look at the URL and then include the file directly - however I want to be quite forgiving with the Urls I accept..</p> <p>If the url is for a specific file I want it to pass though the front controller</p> <p>If the url is for a directory (trailing forward slash) I want to assume they are looking for index.php within that folder</p> <p>The below rule works for urls like this</p> <pre><code>mydomain.com/myadminarea/mysection/action/ (loads mydomain.com/myadminarea/mysection/action/index.php via the front controller) </code></pre> <p>but falls over on urls like this - </p> <pre><code>mydomain.com/myadminarea/mysection/action/index.php </code></pre> <p>that contain a filename (it doesn't use the front controller but just loads the file directly) - I know that the !-f excludes the rewrite rule for files, but I've tried every combination I can think of and the below at least works for urls without filenames. When I try to route EVERY request (except those to the themes folder) I get a server configuration error (500)</p> <p>This is my rule</p> <pre><code>RewriteCond %{REQUEST_FILENAME} !-f RewriteRule !^(themes)/ /myadminarea/index.php [NC,L] </code></pre> <p>edit:</p> <p>Added Condensed front controller </p> <pre><code>// what page is actually being requested? $uri = explode("/", $_SERVER["REQUEST_URI"]); //lose the first element and add index.php the last one if it is blank array_shift($uri); if (end($uri) == ''){ array_pop($uri); $uri[] = 'index.php'; } $page_requested = implode('/', $uri); if ($page_requested == 'myadminarea/index.php'){ $page_requested = false; } includePage($page_requested); function includePage($page_requested){ if ($page_requested &amp;&amp; file_exists(BASE_FILE_PATH . $page_requested) &amp;&amp; is_file(BASE_FILE_PATH . $page_requested)){ include(BASE_FILE_PATH . $page_requested); } else { echo $page_requested; } } </code></pre>
    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.
 

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