Note that there are some explanatory texts on larger screens.

plurals
  1. POMaking a SEO friendly URL for a CMS
    primarykey
    data
    text
    <p>I am trying to create a Content Management System using Codeigniter. I have a page where I display a list of article titles. When any user click on any of the article titles it will take the user to the details of that article in a separate page.</p> <p>I am displaying the article title list using the following code:</p> <pre><code> &lt;a href="&lt;?php echo base_url(); ?&gt;article/&lt;?php echo $row['article_id']; ?&gt;"&gt; &lt;?php echo $row['article_title']; ?&gt;&lt;/a&gt; </code></pre> <p>When any user click on the above link it takes the article_id and go to the following controller </p> <p>Controller:</p> <pre><code>function index($id){ $this-&gt;load-&gt;model('mod_articles'); $data['records']=$this-&gt;mod_articles-&gt;list_articles($id); $this-&gt;load-&gt;view('view_article',$data); } </code></pre> <p>Model :</p> <pre><code> function list_articles($id) { $this-&gt;db-&gt;select('*'); $this-&gt;db-&gt;from('article'); $this-&gt;db-&gt;where('article_id', $id); $query = $this-&gt;db-&gt;get(); return $query-&gt;row_array(); } </code></pre> <p>Now when I display the result, in the browser's address bar the link looks like this-</p> <pre><code> localhost/cms/article/1 //&lt;&lt; here localhost/cms/ is my base_url </code></pre> <p>According to this <a href="http://cmsteachings.com/frienly-urls-good-seo" rel="nofollow">website</a> , an example of good SEO friendly URL is <code>http://www.mysite.com/joomla-seo-tips</code> .</p> <p>Now my question is how to make my URL look like <code>localhost/cms/article/my-article-title</code> instead of showing the id of the article at the end of link?</p> <p>To acheive this should I query for my article titles instead of article ids or there are some better ways to do that? </p> <p>Please share your ideas on this. </p> <p>Thanks in Advance :)</p> <h2>Edit</h2> <p>So, before saving my content should I run following code get the <code>$article_slug</code> and then save it? </p> <pre><code>function create_slug($string){ $slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string); return $slug; } $article_slug= create_slug('My Name '); // as you suggested I will create a new column for this </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.
 

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