Jump to content

[SOLVED] Advice needed "pages on the fly"


Canman2005

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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

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.