Easy & Fast URL Rewriting

Comment facilement et rapidement mettre en place la “réécriture des URL” sur son site pour optimiser son référencement:

/.htaccess

Options +FollowSymLinks

&lt;IfModule mod_rewrite.c&gt;<br />
RewriteEngine On<br />
RewriteBase /<br />
RewriteRule ^index\.php$ - [L]<br />
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
RewriteRule . /index.php [L]<br />
&lt;/IfModule&gt;

/index.php

<?php

$pages = array(
    'mon-permalink-numero-1' => 'blog_1.php',
    'mon-permalink-numero-2' => 'blog_2.php',
    'mon-permalink-numero-3' => 'blog_3.php',
);

if(isset($_SERVER['REQUEST_URI'])) {

    $request_uri = trim($_SERVER['REQUEST_URI'],'/');
    $filename = __DIR__ . '/includes/' . $pages[$request_uri];
   
    if(array_key_exists($request_uri, $pages) && file_exists($filename)) {

        include($filename);
        exit();

    }
    else {
   
        header('HTTP/1.1 404 Not Found');
        header('Location: /'.key($pages));
        exit();
   
    }

}