Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2004
    Location
    Denmark
    Posts
    21

    Mod_rewrite help, can it be done?

    Can the following be done with the use of Mod_rewrite?

    I have the following URLs (with $variables):
    domain.com/view.php?system=$row[system]&type=$row[type]&shortname$row[shortname]

    example (without $variables);
    domain.com/view.php?system=PC&type=Help&shortname=titlenamehere

    With the help of Mod_rewrite I would like to make it look like this;
    domain.com/PCHelp/titlenamehereHelp.htm

    or

    domain.com/PC-Help/titlenamehere-Help.htm

    Is this possible?

  2. #2
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    1,082

  3. #3
    Join Date
    Jan 2004
    Location
    Denmark
    Posts
    21
    Some people seems to have misunderstood my post, so i'll just try and explain it better;

    have to use a .htaccess file ..

    We need to be aware of changing variables.

    This little piece of rewriting code partly does what im looking for, but not just quite (only to illustrate)

    ---
    RewriteEngine On

    RewriteRule ^([^./]+)/([^./]+)/([^./]+).htm$ view.php?system=$1&type=$2&shortname=$3 [L]
    ---

    This would turn an original URL like;
    domain.com/view.php?system=$system&type=$type&shortname=$shortname

    into;
    domain.com/$system/$type/$shortname.htm

    However I want it turned into:
    domain.com/$system$type/$shortname$type.htm

    or

    domain.com/$system-$type/$shortname-$type.htm

    or atlast - without $type after $shortname at the end

  4. #4
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    Err, mod_rewrite works the opposite way.

    It rewrites The URL typed in the browser, to whatever you specify.

    So your wording is not correct, but I hope your understanding of mod_rewrite isn't.

    So what you really want mod_rewrite to do is take a URL such as domain.com/$system$type/$shortname$type.htm and rewrite it to view.php?system=$system&type=$type&shortname=$shortname

    For this to happen, you need to write a regular expression that can distinguish between $system and $type -- this is why error404 said that the second option would be easier, because you can have the regular expression separate between the - in the $system-$key pattern.
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

  5. #5
    Join Date
    Jan 2004
    Location
    Denmark
    Posts
    21
    Originally posted by fyrestrtr


    So what you really want mod_rewrite to do is take a URL such as domain.com/$system$type/$shortname$type.htm and rewrite it to view.php?system=$system&type=$type&shortname=$shortname
    Nope, it's actually the other way around.

    I want to take a URL such as;
    domain.com/view.php?system=$system&type=$type&shortname=$shortname

    and rewrite it to
    domain.com/$system$type/$shortname$type.htm
    or
    domain.com/$system-$type/$shortname-$type.htm

    Sorry if i've expressed myself wrongly, my mistake :/

  6. #6
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    So what do you want the user to type in the browser? the view.php?system= or the /$system-$type/ ?
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

  7. #7
    Join Date
    Jan 2004
    Location
    Denmark
    Posts
    21
    I want the user to type in;

    domain.com/$system$type/$shortname$type.htm
    or
    domain.com/$system-$type/$shortname-$type.htm

  8. #8
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    This is what I thought. You then want to rewrite the domain.com/$system-$type/$shortname-$type.htm into view.php?

    For this,

    RewriteRule ^(.*?)-(.*?)/(.*?)-(.*?).htm$ view.php?system=$1&type=$2&shortname=$3&stype=$4.php

    Should work, although its early.
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

  9. #9

    mod rewrite

    I heard theres a good site called doriat.com discussing about mod rewrite on php scripts.

  10. #10
    Join Date
    Jan 2004
    Location
    Denmark
    Posts
    21
    fyrestrtr > got it working, thanks alot

Posting Permissions

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