Results 1 to 6 of 6

Thread: mod_rewrite Yet Again

  1. #1
    Senior Member
    Join Date
    Mar 2004
    Location
    California
    Posts
    724

    Default mod_rewrite Yet Again

    OK, I'm trying to rewrite URLs like this:

    Code:
    http://www.site.com/index.php?option=com_virtuemart&Itemid=27
    http://www.site.com/index.php?option=com_virtuemart
    To show this in the address bar:

    Code:
    http://www.site.com/store/Itemid=27
    http://www.site.com/store
    Here's what I have in .htaccess:

    Code:
    RewriteEngine on
    RewriteRule ^store(/)?$ ^index.php?option=com_virtuemart([0-9]+)-([a-z]+)
    Does not work, but I'm obviously not getting how this thing works. Any help on this one from you mod_rewrite gurus out there?

  2. #2
    Junior Member
    Join Date
    Nov 2006
    Location
    Waterloo, ON
    Posts
    16

    Default

    Code:
    RewriteEngine on
    RewriteRule ^store$ index.php?option=com_virtuemart
    RewriteRule ^store/Itemid=([0-9]+)$ index.php??option=com_virtuemart&Itemid=$1
    I wrote two lines so it wouldn't have been a mess.

    For the first chunk of RewriteRule, you need to 'capture' a group of characters (with parenthesis) to be reused as variables for the next part. Second part names the variables starting from $1 by the position of the parenthesis.

    The 2 question marks are new to be as well, after a quick search for them.
    Last edited by JackT; 11-30-2007 at 08:03 AM. Reason: Added explanation.

  3. #3
    Junior Member
    Join Date
    Dec 2005
    Posts
    13

    Default

    Joomla will mod_rewrite your urls automatically if you go to site->global configuration->Seo->search engine friendly URLs and click "yes" then rename htaccess.txt to .htaccess in the root of your joomla installation.

  4. #4
    Senior Member
    Join Date
    Mar 2004
    Location
    California
    Posts
    724

    Default

    Quote Originally Posted by AndyP View Post
    Joomla will mod_rewrite your urls automatically if you go to site->global configuration->Seo->search engine friendly URLs and click "yes" then rename htaccess.txt to .htaccess in the root of your joomla installation.
    Right, but usually all that does is replace the "unfriendly" elements with pretend directories ... so "htp://www.site.com/index.php?option=com_virtuemart&Itemid=27" becomes something like "htp://www.site.com/index.php/option/com/virtuemart/Itemid/27"

    Thanks everyone for the help ... the solutions didn't seem to work to change the words "com_virtuemart" to "store", but the customer has decided he doesn't really care that much about it. So I dodged the bullet this time!

  5. #5
    Junior Member
    Join Date
    Apr 2007
    Posts
    11

    Default

    I think Jack was on the right track; he just had two question marks on the second RewriteRule line, and seemed to be missing the leading slash. I also added /? to the regex of the first rule, to make it work for www.site.com/store/ or www.site.com/store (i provided for an optional trailing slash).

    Code:
    RewriteEngine on
    RewriteRule ^/store/?$ /index.php?option=com_virtuemart
    RewriteRule ^/store/Itemid=([0-9]+)$ index.php?option=com_virtuemart&Itemid=$1
    no guarantees this will work, as i'm not a mod_rewrite guru by any stretch of the imagination, but it oughtta be worth a shot

    EDIT: i just noticed this thread is like two months old. oops!

  6. #6
    Senior Member
    Join Date
    Mar 2004
    Location
    California
    Posts
    724

    Default

    Thanks, Dr. Jones. The customer doesn't mind the "virtuemart" id in the URL, so I have stopped tinkering on that particular site.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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