www.webdeveloper.com
Results 1 to 6 of 6

Thread: How do I make links look prettier for better SEO

Hybrid View

  1. #1
    Join Date
    May 2003
    Location
    Florida
    Posts
    38

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440
    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.

  3. #3
    Join Date
    May 2003
    Location
    Florida
    Posts
    38

    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.

  4. #4
    Join Date
    Aug 2012
    Posts
    155
    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
    HTML Code:
    <a href="/<?php echo $row['page_title']; ?>">
    The .htaccess file would then be set up like this
    Code:
    RewriteEngine On
    RewriteEngine On
    RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?page_title=$1
    RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?page_title=$1

  5. #5
    Join Date
    Dec 2012
    Location
    Lahore, Pakistan
    Posts
    10
    To make your urls prettier you will have to write .htaccess and change links inside your php scripts according to specified pattern.

  6. #6
    Join Date
    May 2003
    Location
    Florida
    Posts
    38

    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles