Jump to content

Changing URLs to be SEO-friendly?


galvin

Recommended Posts

This might not be the proper forum to post this, but since I don't know how to do it, I'm starting here  (Feel free to move it to the proper one if it should be moved)

 

I will have a web app where there will be a main page (we'll call it mainpage.php) and there will be a URL extension to pull data from MySQL, like mainpage.php?id=1

 

I will ultimately have thousands of these URLs, i.e...

 

mainpage.php?id=1

mainpage.php?id=2

mainpage.php?id=3

etc, etc.

 

Each of those datasets that are specified by a "id" will have a more SEO friendly description. For example, id of 1 may have a Description in MySQL of "Football Quarterbacks".

 

So in an ideal world, when a visitor goes to mainpage.php?id=1, I would prefer the URL to display mainpage.php/football_quarterbacks

 

And more importantly, I would prefer that once my pages start showing up in Google Search results, the URL would display as mainpage.php/football_quarterbacks instead of mainpage.php?id=1

 

Is this type of "URL-changing" possible?

 

If so, how do I get Google Search to show the more user friendly version?

 

These are probably loaded questions, so if there are any online resources that discuss the topic(s) further, please share :)

 

Thanks!

 

 

Link to comment
Share on other sites

The first thing you will need to do is edit your .htaccess file to look something like this:

 

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ router.php?request=$1 [L]
</IfModule>

 

This takes all requests that aren't referencing a file or directory, and sends to your script named router.php. It passes the string of your request to a $_GET variable called request. For example, if you went to the page http://www.example.com/test, the request would look like this: router.php?request=test. You could then access the request with $_GET['request'] from within router.php. This is what my router.php looks like:

 

<?php
error_reporting(0);

if ( $_GET['request'] ) {
$page = $_GET['request'] . ".php";

if ( file_exists($page) ) {
	require_once($page);
} else {
	require("404.php");
}
} else {
require('index.php');
}

 

Just make sure you can't include remote files or you will have a RFI vulnerability. Hope this helps. If you have any other questions you can post them or PM me.

Link to comment
Share on other sites

I forgot to address your question about having the description of the mysql row in the url instead of the ID. You would need to create a new field in your table called "seo_url" or something similar. Whenever you are inserting a row into your table, you would need to also populate your new field. I made a function you could use the convert the description to put in your seo_url field:

 

<?php
function pretty_url($name) {
return preg_replace("/[^0-9,a-z,A-Z,-]/", "", str_replace(" ", "-", strtolower(trim($name))));
}
?>

 

Now when you are selecting the row from your php file, the sql query would need to look like this:

 

SELECT * FROM `my_table` WHERE `seo_url` = '{$_GET['request']}' LIMIT 1;

Link to comment
Share on other sites

I'm replying because I work for an SEO company.  Keep in mind that a majority of SEO work boils down to quality link builing more than anything else.  Five years ago, the "on page" factors (the actual code of your website) had to be spotless to generate a decent ranking on Google.  Today, as Google, Yahoo, and Bing completely ignore META tags, 90% of your SEO is going to come from building those quality links.

 

In about 2-3 years, Google will change that, and may go to social media (or so I've heard them say on NPR).  But for now, focus more on the link building.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.