I only learn to program in PHP. When I just turn on the main page (for example, site.ru), then it writes that this is the main one, and if you go to site.ru / index or site.ru / photo, then you simply get an error 404 .. I follow the example of a video tutorial, there everything in the guy works.

<?php header("Content-Type: text/html; charset=utf-8"); if ($_SERVER['REQUEST_URI'] == '/') { $Page = 'index'; $Module = 'index'; } else { $URL_Path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $URL_Parts = explode('/', trim($URL_Path, ' /')); $Page = array_shift($URL_Parts); $Module = array_shift($URL_Parts); if (!empty($Module)) { $Param = array(); for ($i = 0; $i < count($URL_Parts); $i++) { $Param[$URL_Parts[$i]] = $URL_Parts[++$i]; } } } if ($Page == 'index') echo 'Главная'; else if ($Page == 'photo') echo 'photo'; ?> 

Htaccess file

 RewriteEngine on RewriteBase / Options All -Indexes RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^resource/(.*)$ resource/$1 [L] RewriteRule ^.*$ [NC,L] RewriteRule ^.*$ index.php [NC,L] 

    2 answers 2

    This code works. Problems that could arise

    1. mod_rewrite does not work in apache . About what it is and how to set it up described in detail here.

    2. Apache does not see the .htaccess file. Well, there are already very many options - so google for help

    • I wonder what I did in the video lesson, and used the same hosting as in the lesson - Maxim Kokhansky
    • On a hosting mod_rewrite can be disabled and enabled on request. - DOC_tr
     if ($Page == 'index') include('page/index.php'); function Menu () { if $Menu = '<a href="/index">Главная</a>'; echo '<a href="/">Главная</a>'; } 
    • Use the {} button to highlight a code or indents with four spaces. - AivanF.
    • Try to write more detailed answers. Explain what is the basis of your statement? - Nicolas Chabanovsky