When creating an article in a separate field in the database, the title of the article fits into my transliteration. But how to make the article open not at http://site.ru/articles.php?id=ID, but at http://site.ru/nazvanie.html ? The article is displayed as


if($id) { $counts = @ mysql_result(mysql_query('SELECT COUNT(*) FROM `articles` WHERE `id`='.$id.' AND `moderation`="1";'), 0); if($counts==0) { echo '<div class="alert alert-error">Статьи не существует!</div>'; echo '</article>'; require 'system/foot.php'; exit; } $row = mysql_fetch_assoc(mysql_query("SELECT * FROM `articles` WHERE `id`='".$id."' AND `moderation`='1'")); 

    2 answers 2

    In the .htaccess file, in the root of the site, add an entry

      RewriteEngine On RewriteRule ^(.*)\.html$ /articles.php?name=$1 [L] 

    And slightly change the query to the database. Instead

     id='.$id.' 

    to write

     translite_name="'.mysql_escape_string($_GET['name']).'" 
    • But how to determine that the article does not exist? - vitagame
    • Something like this: $ row = mysql_fetch_assoc (mysql_query ("SELECT * FROM articles WHERE translite_name =" '. Mysql_escape_string ($ _ GET [' name ']).' "AND moderation = '1'")); if (! $ row ['ID']) {echo '<div class = "alert alert-error"> Articles do not exist! </ div>'; echo '</ article>'; require 'system / foot.php'; exit; } And the code if ($ id) {....} Remove completely - Pavel Vershinin
    • More precisely if (! $ Row ['chpy']) - vitagame
     RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^(.*)$ articles.php?id=$1 [L,QSA] 

    when typing http://site.ru/nazvanie.html

     $_GET["id"] = "nazvanie.html"; 
    • If you do it then it works only this way - site.ru/nazvanie.html?id=ID - vitagame
    • duck you're not doing the right thing ... - johniek_comp
    • Yes, everything is fine, it works. - vitagame