PDA

View Full Version : Resolved Rewriting URLs with mod_rewrite



Schmoopy
06-10-2011, 09:49 AM
Hi guys,

I could do with some help if you'd be so kind...

I know a little about mod_rewrite, but have got to the stage now where I need someone with more knowledge in this area to help me out.

Here's the situation:

I've created a shop on one of my sites, and need to be able to map URLs to products.

Example 1:

URL: http://mysite.dev/shop/

This takes you to the main shop page, which has categories within it, e.g:

Clothing, Artwork and DVDs

Example 2:

URL: http://mysite.dev/shop/clothing

This takes you to the clothing section, within the shop, which then has multiple categories: Mens and Womens.

Example 3:

URL: http://mysite.dev/shop/clothing/mens/

This should take you to a section that has all the products listed under mens clothing.

The problem is I don't know how to write this in htaccess, since I need to rewrite on the product ID too, for example:

URL: http://mysite.dev/shop/clothing/mens/cloud_nine_black

This should redirect to a page that has the actual product on it, under the mens category.

Any ideas? I'm completely stumped. Here is my htaccess code so far:



DirectoryIndex home.php

Options +FollowSymLinks
Options -Indexes

RewriteEngine On
RewriteBase /

RewriteRule ^friends/$ friends.php [L]
#RewriteRule ^shop/(.*)/(.*)/$ shop.php?category=$1&prod=$2 [L]
RewriteRule ^friends/(.*)/$ friends.php?id=$1 [L]
RewriteRule ^friends/(.*)$ friends.php?id=$1 [L]
RewriteRule ^tags/(.*)$ tags.php?tag=$1 [L]
#RewriteRule ^shop/(.*)/$ shop.php?category=$1 [L]

RewriteRule ^shop/(.*)/(.*)$ shop.php?category=$1&prod=$2 [L]
RewriteRule ^shop/(.*)$ shop.php?category=$1 [L]

RewriteRule ^links$ links.php
RewriteRule ^ethics$ ethics.php
RewriteRule ^tags$ tags.php
RewriteRule ^friends$ friends.php
RewriteRule ^blog$ blog.php
RewriteRule ^downloads$ downloads.php
RewriteRule ^stockists$ stockists.php
RewriteRule ^contact$ contact.php
RewriteRule ^home$ home.php
RewriteRule ^about_us$ about_us.php
RewriteRule ^shop$ shop.php
RewriteRule ^basket$ basket.php
RewriteRule ^thanks$ thanks.php
RewriteRule ^terms$ terms.php
RewriteRule ^error$ error.php

ErrorDocument 404 /error

# BEGIN Gzip
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</IfModule>
# END Gzip


Any help you can give is greatly appreciated.

Many thanks,

Jack

Schmoopy
06-11-2011, 12:51 PM
This has now been resolved.

Restructured how the URLs were mapped and it now works :)