How do I make links look prettier for better SEO
The main navigation menu on my index.php website is being generated using a "while loop" and generating the menue from a table in my MYSQL database and each menu choice is dymanically generated using php and refering to the "auto incremented" id from the MYSQL table.
For example, index.php?subject=1, and when the link is being clicked on, the <h2> heaer of each page is being dymanically generated using the $_GET super global and a mysql_fetch_array so that the menu name shows in the <h2> tag. For example. will show "Contacts", or "Our History".
The problem is when you look in the address bar of each browser it will just show the ugly index.php?subject=1 or index.php?subject=2 and so on. What I would like to happen is have the dynamically generated menu name show in the address bar instead for better SEO. (i.e. index.php/contact or index.php/our history).
In other words, I want that ugly ?=... stuff to be hidden and something more visually apealing show in the address bar. Can someone please help me with this?
I had a web site that did it like this www.mywebsite.com/20121209355/title-of-my-page
The numeric part was the publish date in the form of yyyymmdd appended with the article number nnn, and the Title of the article converted to lower case, and spaces replaced with hyphens. Not real pretty but it worked.
good 4 you.
That's good to hear but I don't know how to do that because I don't know how to change what appears in the address window using PHP. Your reply didn't help me at all because you did not explain how to do anything.
You need to use .htaccess and modrewrite to do this. But you can't change id numbers to the required text so the best way to get it working you you need is to add another column to your database table that will hold your friendly url page name, so lets say you add a column called page_title and for each page add a friendly title (without spaces) like our_history.
Then your links would be set up like this
The .htaccess file would then be set up like this
<a href="/<?php echo $row['page_title']; ?>">
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?page_title=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?page_title=$1
To make your urls prettier you will have to write .htaccess and change links inside your php scripts according to specified pattern.
Thank you so much guys!
Guys, thank you so much for all your help. I have heard of this .htaccess thing before but I don't know dittly squat about it...yet. Now I'm on a mission to surf google until I'm blue in the face and learn everything about htaccess.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread