Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Step By Step instruction about create SEO friendly URL with dynamic content using PHP and .htaccess mod redirection. Friendly URLs improves your site search engines ranking. Before trying this you have to enable mod_rewrite.so module at httpd.conf. It’s simple just few lines of PHP code converting title data to clean URL format.</p> <p><strong>Database</strong></p> <p>Sample database blog table columns id, title, body and url.</p> <pre><code>CREATE TABLE `blog` ( `id` INT PRIMARY KEY AUTO_INCREMENT, `title` TEXT UNIQUE, `body` TEXT, `url` TEXT UNIQUE, ); </code></pre> <p><strong>Publish.php</strong></p> <p>Contains PHP code. Converting title text to friendly url formate and storing into blog table.</p> <pre><code>&lt;?php include('db.php'); function string_limit_words($string, $word_limit) { $words = explode(' ', $string); return implode(' ', array_slice($words, 0, $word_limit)); } if($_SERVER["REQUEST_METHOD"] == "POST") { $title = mysql_real_escape_string($_POST['title']); $body = mysql_real_escape_string($_POST['body']); $title = htmlentities($title); $body = htmlentities($body); $date = date("Y/m/d"); //Title to friendly URL conversion $newtitle = string_limit_words($title, 6); // First 6 words $urltitle = preg_replace('/[^a-z0-9]/i', ' ', $newtitle); $newurltitle = str_replace(" ", "-", $newtitle); $url = $date . '/' . $newurltitle . '.html'; // Final URL //Inserting values into my_blog table mysql_query("insert into blog(title,body,url) values('$title','$body','$url')"); } ?&gt; &lt;!--HTML Part--&gt; &lt;form method="post" action=""&gt; Title: &lt;input type="text" name="title"/&gt; Body: &lt;textarea name="body"&gt;&lt;/textarea&gt; &lt;input type="submit" value=" Publish "/&gt; &lt;/form&gt; </code></pre> <p><strong>Article.php</strong></p> <p>Contains HTML and PHP code. Displaying content from blog table.</p> <pre><code>&lt;?php include('db.php'); if($_GET['url']) { $url =mysql_real_escape_string($_GET['url']); $url = $url . '.html'; //Friendly URL $sql = mysql_query("select title,body from blog where url='$url'"); $count = mysql_num_rows($sql); $row = mysql_fetch_array($sql); $title = $row['title']; $body = $row['body']; } else { echo '404 Page.'; } ?&gt; &lt;!-- HTML Part --&gt; &lt;body&gt; &lt;?php if($count) { echo "&lt;h1&gt;$title&lt;/h1&gt;&lt;div class='body'&gt;$body&lt;/div&gt;"; } else { echo "&lt;h1&gt;404 Page.&lt;/h1&gt;"; } ?&gt; &lt;/body&gt; </code></pre> <p><strong>.htaccess</strong></p> <p>URL rewriting file. Redirecting original URL 9lessons.info/article.php?url=test.html to 9lessons.info/test.html</p> <pre><code>RewriteEngine On RewriteRule ^([a-zA-Z0-9-/]+).html$ article.php?url=$1 RewriteRule ^([a-zA-Z0-9-/]+).html/$ article.php?url=$1 </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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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