Forum Moderators: phranque

Message Too Old, No Replies

Mod-Rewrite issues

         

memyselfandi

10:39 am on May 21, 2009 (gmt 0)

10+ Year Member



Hi all,

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]

g1smd

11:01 am on May 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Check previous threads. This question is asked (roughly) every two to three days here.

I have posted in two similar threads in the last couple of hours.

Please provide your example code for discussion.

memyselfandi

11:21 am on May 21, 2009 (gmt 0)

10+ Year Member



Sorry if you get hundreds of these, I am new to this and really struggling to get to grips with it.

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]

g1smd

12:56 pm on May 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



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.