Canman2005 Posted September 3, 2008 Share Posted September 3, 2008 Hi all Im building a little shopping cart and wondered what everyones thoughts were. Is it better to have my URL as http://www.website.com/shop?productid=12 or is it better to have http://www.website.com/chocolate_biscuits.html For search engines, is it better to use the name of the page or a product ID. If you think using the name, such as "chocolate_biscuits.html" then is there a way to dynamically create "chocolate_biscuits.html" on the fly using a template and pulling product information from a database? The reason I ask is that I have seen a site which manages to create a HTML page on the fly which has the same filename as the product they are displaying, so in the database they have Large Chocolate Biscuits as a product title, and somehow its managing to create a page such as large_chocolate_biscuits.html on the fly using a the templated PHP page and pulling the required data from the database that relates to that product. I did notice at the end of each URL they have something like p-435.html I can only asume that is the ID number of the product. Can someone shed some lights on this? Thanks so much Ed Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted September 3, 2008 Share Posted September 3, 2008 you can use apache's mod_rewrite to change something like webpage.com/stuff/more_stuff.html to something like webpage.com/page.php?val1=stuff&val2=more_stuff it creates the illusion of them using a .html page for everything, when in truth it's just a user friendly url for a php page... this is likely the method the website you are describing is using. Quote Link to comment Share on other sites More sharing options...
Canman2005 Posted September 3, 2008 Author Share Posted September 3, 2008 Is it a good idea to do it that way? will it be picked up by search engines etc? Does anyone have a good tutorial on how to use the mod_rewrite? thanks Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted September 3, 2008 Share Posted September 3, 2008 major search engine spiders can "pick up" pretty much any url. For the very technical: http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html For the people who probably don't want to scratch out their eyes: http://www.workingwith.me.uk/articles/scripting/mod_rewrite I just found those on google, of which there are many more Quote Link to comment Share on other sites More sharing options...
Canman2005 Posted September 3, 2008 Author Share Posted September 3, 2008 wicked, thanks guys, helped loads. If anyone is interested, to do this 1: create a .htaccess file with the contents as RewriteEngine on RewriteRule ^(.*).php$ content.php?url=$1&%{QUERY_STRING} 2: Then create a php page called "content.php" and add the following <?php $db_name ="dbname"; $server = "localhost"; $dbusername = "usr"; $dbpassword = "pwd"; $connection = mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error()); $db = mysql_select_db($db_name,$connection)or die(mysql_error()); $sql = "SELECT * FROM `table` WHERE `url` = '".$_GET['url']."'"; $show = @mysql_query($sql,$connection) or die(mysql_error()); while ($row = mysql_fetch_array($show)) { print $row['title']; } ?> 3: Now create a table using the following CREATE TABLE `table` ( `id` int(100) NOT NULL auto_increment, `title` varchar(255) NOT NULL, `url` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; INSERT INTO `table` (`id`, `title`, `url`) VALUES (1, 'About Us', 'aboutus'); 4: Navigate to the same URL that you have stored your "content.php" and rather than typing "content.php", try typing "aboutus.php" and it should pull through the title of the row in the database which has the same URL as you have entered. If you're running WAMP, to enable mod_rewrite, you need to open the "httpd.conf" file and uncomment LoadModule rewrite_module modules/mod_rewrite.so so #LoadModule rewrite_module modules/mod_rewrite.so becomes LoadModule rewrite_module modules/mod_rewrite.so you can find the "httpd.conf" file if you click on the WAMP icon and go to config files Any probs, get in touch Quote Link to comment 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.