I have a front controller in my PHP project. Here is the code;
.htaccess
file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [PT,L]
</IfModule>
index.php
file
<?php
list($url) = explode('?', $_SERVER['REQUEST_URI']);
$url = trim(trim($url), '/');
if(!file_exists('pages/'.$url.'.php')
header('Location: 404.html');
require_once 'inc/head.php';
require_once 'pages/'.$url.'.php';
require_once 'inc/foot.php';
?>
I assumed every requested URL must go through index.php file. But if there is a \
(as %5C) in URL server answer is "Not Found".
Questions;
- Why there is an exception for
\
character? Is there any characters like that? - What is the reqular use of
\
character to make Apache search for a file? Why not just ignore? - Where Apache looks and not founds the file?
Note: My system is Windows with Apache 2.2.21 and PHP 5.3.10. Note2: This is just an example code, so do not offer a better way.