RSS Forums RSS
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 456 | Replies: 12
Reply
Join Date: Sep 2008
Posts: 22
Reputation: servantofgod is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
servantofgod servantofgod is offline Offline
Newbie Poster

Rewrite advice: What is the best solution to this problem?

  #1  
Sep 28th, 2008
Looking to rewrite the pages of a company I work for, www.whatsshopping.com. The product pages produce URL's as such:

http://www.whatsshopping.com/product...2&cat=LG483BLK

Looking to if possible, rewrite the pages to reflect the product name or category name in the url.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2008
Posts: 41
Reputation: FlashCreations is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
FlashCreations's Avatar
FlashCreations FlashCreations is offline Offline
Light Poster

Re: Rewrite advice: What is the best solution to this problem?

  #2  
Sep 28th, 2008
Well I would suggest giving each product a category (that has a cat number) and then within each category, give each product number (id). Then the address would be something like: products.php?cat=5&id=1
With that you could also use it to browse each category with one PHP script.
Ex.
products.php?cat=5

Try looking at some popular shopping sites such as Amazon and see how they do it. It's always best to learn from the Pro's!!!
Last edited by FlashCreations : Sep 28th, 2008 at 4:39 pm.
FlashCreations
For great articles on technology today, see FlashCreations' Computer Help and FAQ!
Trying to find freeware that is actually free, then why not try out Soogle Search. It's the best way to search the web for freeware!!!
Reply With Quote  
Join Date: Sep 2008
Posts: 22
Reputation: servantofgod is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
servantofgod servantofgod is offline Offline
Newbie Poster

Re: Rewrite advice: What is the best solution to this problem?

  #3  
Sep 28th, 2008
I'm sorry, I didn't explain it correctly, that is currently how it is. If you click on a product, it currently displays the category # and product id# For example here is an anime movie : http://www.whatsshopping.com/product...65&cat=1931201

the ban= is actually the category id, and cat= is actually the product id.

I am trying to figure out how I can get the url to reflect the product's name instead of ban & cat. How exactly to get it to call the product name from the database instead of those two. And if possible will it have a negative effect if there is more than one product with the same name?
Reply With Quote  
Join Date: Sep 2008
Posts: 41
Reputation: FlashCreations is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
FlashCreations's Avatar
FlashCreations FlashCreations is offline Offline
Light Poster

Re: Rewrite advice: What is the best solution to this problem?

  #4  
Sep 28th, 2008
How about then using something like this:
product.php?cat=3&product=Studio-8
Amazon uses a system that has a product name with spaces replaced with dashes and then a number (Probably the product number). Example of a Amazon URL:
www.amazon.com/Macromedia-Studio-Win-Mac-Version/dp/B000CS3S04/ref=sr_1_6?ie=UTF8&s=software&qid=1222636154&sr=8-6
Last edited by FlashCreations : Sep 28th, 2008 at 6:11 pm.
FlashCreations
For great articles on technology today, see FlashCreations' Computer Help and FAQ!
Trying to find freeware that is actually free, then why not try out Soogle Search. It's the best way to search the web for freeware!!!
Reply With Quote  
Join Date: Sep 2008
Posts: 22
Reputation: servantofgod is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
servantofgod servantofgod is offline Offline
Newbie Poster

Re: Rewrite advice: What is the best solution to this problem?

  #5  
Sep 28th, 2008
That would work, now where do you suppose I would find someone who can explain to me how to code that.
Reply With Quote  
Join Date: May 2008
Location: Swindon, UK
Posts: 185
Reputation: xan is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 32
xan's Avatar
xan xan is offline Offline
Junior Poster

Re: Rewrite advice: What is the best solution to this problem?

  #6  
Sep 29th, 2008
The rewrites will be the easy part as these are just REGEX in your .htaccess file.

The rest of the work would be a huge task, all your links on all pages would need to be updated to the new format.

Take a look at http://www.workingwith.me.uk/article...ng/mod_rewrite for rewrite descriptions and tutorials.
Don't expect other people to help you if you won't help yourself, expect a point in the right direction, not a complete solution.
Reply With Quote  
Join Date: Sep 2008
Posts: 22
Reputation: servantofgod is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
servantofgod servantofgod is offline Offline
Newbie Poster

Re: Rewrite advice: What is the best solution to this problem?

  #7  
Sep 30th, 2008
Well basically the way my site works is this. It is dynamic. I have only four hard coded pages. These four pages are the ones that produce dynamic URLs.

categories_and_featured_products.php, subcategories_and_featured_products.php, products.php, and productsincategories.php.

Now the pages pull information from the MYSQL database whenever someone browses the sight, so to someone who is not tech savvy it seems as if we have thousands and thousands of pages. Really those thousands of pages are only four pages with different information generated each time. For example the 'mobile electronics: mp4' page's url looks like this:

http://www.whatsshopping.com/subcate...pid=46&cid=331

but really it is just subcategories_and_featured_products.php, with information called from the database.

So my issue here is creating and installing the right .htaccess file. Redoing the links on the site is not a problem because I have a constant header and footer.

Can anyone tell me if the following is correct for my .htaccess file? If not, what more do I need?

Options +FollowSymLinks
RewriteEngine on
RewriteRule subcategories_and_featured_products-pid-(.*)-cid-(.*)\.htm$ subcategories_and_featured_products.php?pid=$1&cid=$2

Options +FollowSymLinks
RewriteEngine on
RewriteRule productsincategories-ban-(.*)-cat-(.*)\.htm$ productsincategories.php?ban=$1&cat=$2

Options +FollowSymLinks
RewriteEngine on
RewriteRule products-ban-(.*)-cat-(.*)\.htm$ products.php?ban=$1&cat=$2

Options +FollowSymLinks
RewriteEngine on
RewriteRule categories_and_featured_products-pid-(.*)\.htm$ categories_and_featured_products.php?pid=$1
Reply With Quote  
Join Date: May 2008
Location: Swindon, UK
Posts: 185
Reputation: xan is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 32
xan's Avatar
xan xan is offline Offline
Junior Poster

Re: Rewrite advice: What is the best solution to this problem?

  #8  
Sep 30th, 2008
First, you do not need to declare the options and enable the rewriteengine more than once at the top of the file.

Also, I am assuming products and catagories will only be numbers, this being the case it would be good practice to only allow numbers in the query string rather than anything.
This can be done by putting ([0-9]+) which means only allow characters 0 through 9 and the + means 1 or more.
Options +FollowSymLinks
RewriteEngine on

RewriteRule categories_and_featured_products-pid-([0-9]+)\.htm$ categories_and_featured_products.php?pid=$1 

RewriteRule subcategories_and_featured_products-pid-([0-9]+)-cid-([0-9]+)\.htm$ subcategories_and_featured_products.php?pid=$1&cid=$2

RewriteRule productsincategories-ban-([0-9]+)-cat-([0-9]+)\.htm$ productsincategories.php?ban=$1&cat=$2

RewriteRule products-ban-([0-9]+)-cat-([0-9]+)\.htm$ products.php?ban=$1&cat=$2 
Don't expect other people to help you if you won't help yourself, expect a point in the right direction, not a complete solution.
Reply With Quote  
Join Date: Sep 2008
Posts: 22
Reputation: servantofgod is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
servantofgod servantofgod is offline Offline
Newbie Poster

Re: Rewrite advice: What is the best solution to this problem?

  #9  
Oct 1st, 2008
Thanks alot. I myself have little programming experience, so whatever information is given is helpful. Actually, products and categories will be less numbers and more actual text. We are reforming that for SEO purposes as well. Can I safely remove the 0-9, or should it be replaced with an alternative?
Last edited by servantofgod : Oct 1st, 2008 at 12:14 am.
Reply With Quote  
Join Date: May 2008
Location: Swindon, UK
Posts: 185
Reputation: xan is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 32
xan's Avatar
xan xan is offline Offline
Junior Poster

Re: Rewrite advice: What is the best solution to this problem?

  #10  
Oct 1st, 2008
I would suggest looking into regex extensively as there are many options for this.

if you are using letters, you can define which particular ones you will allow any whether they are caps, lower case or case insensitive.

In rewrites your regex goes in the (), conditions go in the [] and modifiers go between the ] and ), for example, to allow all lower or upper character(Latin, Greek, and Cyrillic character sets only) use ([a-zA-z]+) if you want to internationalize and allow accented characters you would use ([a-z]+) and add [NC] to the end of the line.

Take a search online for regex, specifically for mod_rewrite as there are slight differences you need to use in the .htaccess file compared to some programming/scripting languages.
Last edited by xan : Oct 1st, 2008 at 12:28 am.
Don't expect other people to help you if you won't help yourself, expect a point in the right direction, not a complete solution.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:49 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC