mod_rewrite Yet Again

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Frank Hagan
    Senior Member
    • Mar 2004
    • 724

    #1

    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?
  • JackT
    Junior Member
    • Nov 2006
    • 16

    #2
    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, 08:03 AM. Reason: Added explanation.

    Comment

    • AndyP
      Junior Member
      • Dec 2005
      • 13

      #3
      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.

      Comment

      • Frank Hagan
        Senior Member
        • Mar 2004
        • 724

        #4
        Originally posted by AndyP
        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!

        Comment

        • Dr. Jones
          Junior Member
          • Apr 2007
          • 11

          #5
          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!

          Comment

          • Frank Hagan
            Senior Member
            • Mar 2004
            • 724

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

            Comment

            Working...