Results 1 to 2 of 2

Thread: Rewriting URLs with mod_rewrite

  1. #1
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Question Rewriting URLs with mod_rewrite

    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:

    Code:
    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
    Last edited by Schmoopy; 06-11-2011 at 12:52 PM.

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    This has now been resolved.

    Restructured how the URLs were mapped and it now works

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •