rewrite in subdirectory ipod/?product=itouch

Discussion in 'Apache' started by thermal, Dec 19, 2008.

  1. #1
    Looking for rewrite help in htaccess from this
    http://www.buy-it-here.net/ipod/?product=itouch
    to this
    http://www.buy-it-here.net/ipod/itouch.html
    is this possible
    Thanks in advance for any help
     
    thermal, Dec 19, 2008 IP
  2. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #2
    If you actually want to go from/to in the direction you said, you can use something like this in your ipod directories htaccess.

    RewriteEngine on
    RewriteBase /ipod/
    
    RewriteCond %{QUERY_STRING} ^product=(.+)$
    RewriteRule ^/?(index\.php)?$ %1.html
    Code (markup):
    however if you actually want to go in the other direction like people commonly do, you can use something like this in the same htaccess.

    RewriteEngine on
    RewriteBase /ipod/
    
    RewriteRule /?([^/]+)\.html$ ?product=$1
    Code (markup):
     
    joebert, Dec 19, 2008 IP
  3. thermal

    thermal Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    joebert thanks
    I would prefer this way buy-it-here.net/ipod/itouch.html so I would use the first htaccess.
    I will test this and see what looks better and if it works on my hosting account.
    I have been putting the htaccess file in the ipod directory is that a problem
    Thanks
     
    thermal, Dec 20, 2008 IP
  4. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #4
    I think you're either going to want to use the second set of rules, or forget about mod_rewrite all together for this unless you're just looking to bridge an old GET variable system to a new static HTML system. I've never seen anyone actually want to rewrite their URLs ass-backwards like that, I just included it because of the way you worded your request. :)

    If you actually have an /ipod/ directory, it's best to place rewrites specific to that directory in there to prevent them from slowing down the server due to being evaluated for every request made to the server in the parent directories htaccess.

    It is ALWAYS a better use of resources to have separate htaccess files for rewrites in their appropriate directories instead of placing all of them in the htaccess file of the DocumentRoot directory. If you want to see why this is in detail, I suggest looking into the RewriteLog directive.
     
    joebert, Dec 20, 2008 IP