Forum Moderators: phranque
I am hoping you can help.
I have a website: http://www.example.co.uk.
When customers view my products they see the URL as follows:
http://www.example.co.uk/WebsitePages/description.php?productId=248
(the id changes for the appropriate product)
I want to change this so that the URL reads http://www.example.co.uk/(the product's name)
Ideally I would like it to pull the products name from the MySQL database, however I don't mind writing a rule for each product if needs be.
I am struggling to figure out how to write this code into a .htaccess file.
Please can someone help?
Thanks
[edited by: coopster at 1:30 pm (utc) on May 21, 2009]
[edit reason] please use example.com, thanks! [/edit]
I would pay someone, however the company which built my site made a right mess of it and it cost me a fortune to get it fixed.
I have found this rule:
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /WebsitePages/description.php?productId=$1 [L]
This makes the:
http://www.example.co.uk/WebsitePages/description.php?productId=248
appear as:
http://www.example.co.uk/248.html
However I would like to change the 248 part to the name of the product.
Are you able to help, or point me in the direction of a thread which talks you through it?
Sorry to be a pain in the backside.
[edited by: jdMorgan at 1:31 pm (utc) on May 21, 2009]
[edit reason] example.co.uk [/edit]
This makes the:
http://www.example.com/WebsitePages/description.php?productId=248
appear as:
http://www.example.com/248.html
It does nothing of the sort. A rewrite does not *make* URLs.
What it does it take an incoming request for the URL: http://www.example.com/248.html and fetch the content from the internal filepath: /WebsitePages/description.php?productId=248
This is a common misconception.
So, in order for the '248' to be the name of the product, that is what you are going to have to put in the links in the pages of the site. It is links that 'define' the URL.
You'll also need to include the '248' in the URL so that the database will be return the right content. There is no way for .htaccess to be able to map 'red widget' and '248' all on it's own.
So, you'll use URLs like example.com/24-red-widget and use a rewrite to fetch the content from /description.php?productid=$1&productname=$2 making sure that if the value for $2 does not match what is in the database for that product that you issue a redirect to the correct URL.
This stops your competitors linking to example.com/248-this-product-is-junk and your site directly returning valid content at that URL.