galvin Posted August 18, 2011 Share Posted August 18, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/245107-changing-urls-to-be-seo-friendly/ Share on other sites More sharing options...
jjacquay712 Posted August 18, 2011 Share Posted August 18, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/245107-changing-urls-to-be-seo-friendly/#findComment-1259000 Share on other sites More sharing options...
jjacquay712 Posted August 18, 2011 Share Posted August 18, 2011 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; Quote Link to comment https://forums.phpfreaks.com/topic/245107-changing-urls-to-be-seo-friendly/#findComment-1259006 Share on other sites More sharing options...
galvin Posted August 18, 2011 Author Share Posted August 18, 2011 Thanks so much. This makes sense after a quick read through. I'm at work now but will try to mess with it tonight. If I have any questions, I'll PM you. But I'll do my best to not bother you Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/245107-changing-urls-to-be-seo-friendly/#findComment-1259036 Share on other sites More sharing options...
TapeGun007 Posted August 18, 2011 Share Posted August 18, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/245107-changing-urls-to-be-seo-friendly/#findComment-1259058 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.