RewriteRule Problem

Discussion in 'PHP' started by NOKProduction, Jun 25, 2009.

  1. #1
    Hi, i have a problem about RewriteRule, when i was add value to url, i can not get that value with php.

    For Example;
    My dynamic url is : domain.com/?a=x&b=y&c=x ,
    I can set : domain.com/x/y/z.html

    But when a add to url ?d=w i can not get that value,

    For Example;
    if url like domain.com/x/y/z.html?d=w i can not get d's value.

    What is the problem ?
     
    NOKProduction, Jun 25, 2009 IP
  2. Wrighty

    Wrighty Peon

    Messages:
    199
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That's because you've got to add a rule for it.

    Paste your current rule & I'll modify it! :)
     
    Wrighty, Jun 25, 2009 IP
  3. NOKProduction

    NOKProduction Greenhorn

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.html$ product.php?name=$2&id=$3 [L]
     
    NOKProduction, Jun 25, 2009 IP
  4. Wrighty

    Wrighty Peon

    Messages:
    199
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    For a start that wouldn't do what you wanted as you're not using $1 ... :p

    But try this:

    RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.html\?([^/]*)$ product.php?name=$2&id=$3$4 [L]
     
    Wrighty, Jun 25, 2009 IP
  5. NOKProduction

    NOKProduction Greenhorn

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #5
    I was use that but didn't ok, $1 is unnecessary variable so i don't use that, when i use that code ( your code ), i see page not found.

    For example;
    Url is : httq://localhost/content/1258/xxx-yyy-zzzz.html?page=2

    Error: The requested URL /content.html/1258/xxx-yyy-zzzz.html was not found on this server.


    So, system automatic add ".html" to first variable. ( for example blabla.com/content/blabla/blabla.html )
     
    NOKProduction, Jun 25, 2009 IP
  6. Wrighty

    Wrighty Peon

    Messages:
    199
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    if it's always /content - why not add that into the rewriterule?
     
    Wrighty, Jun 25, 2009 IP
  7. NOKProduction

    NOKProduction Greenhorn

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #7
    Because when i use direct content in htaccess, it was always add ".html" after /content

    For example;

    Url is : httq://localhost/content/1258/xxx-yyy-zzzz.html
    Htaccess : RewriteRule ^content/([^/]*)/([^/]*)\.html$ product.php?id=$1&name=$2 [L]
    Error: The requested URL /content.html/1258/xxx-yyy-zzzz.html was not found on this server.

    But if i a use ([^/]*) it's ok.

    For example;

    Url is : httq://localhost/content/1258/xxx-yyy-zzzz.html
    Htaccess : RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.html$ product.php?id=$1&name=$2 [L]
    Error: No error, it's ok.

    Not: I'm using appservnetwork at windows xp.
     
    NOKProduction, Jun 25, 2009 IP
  8. Wrighty

    Wrighty Peon

    Messages:
    199
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    let's try some RegExp ... :

    RewriteRule ^content\/([a-zA-Z0-9\-\_]+)\/([a-zA-Z0-9\-\_]+)\.html\?([a-zA-Z0-9\-\_]+)$ product.php?id=$2&name=$3$4

    If your server supports RegExp - then that' what it will be I think ... Failing that - I'll test it on my server & perfect it. :)
     
    Wrighty, Jun 25, 2009 IP
  9. NOKProduction

    NOKProduction Greenhorn

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #9
    Hmss, so i think appserv has a problem.
     
    NOKProduction, Jun 25, 2009 IP
  10. Wrighty

    Wrighty Peon

    Messages:
    199
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Have you not got a live server that you can test on? It's best to test htaccess rewrites online - testing locally can sometimes cause problems.
     
    Wrighty, Jun 25, 2009 IP
  11. NOKProduction

    NOKProduction Greenhorn

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #11
    I have got a live server, but i'm working localhost always, and i usually test script's action, i will change my local server :)
     
    NOKProduction, Jun 25, 2009 IP
  12. Wrighty

    Wrighty Peon

    Messages:
    199
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #12
    XAMP is good :)
     
    Wrighty, Jun 25, 2009 IP
  13. NOKProduction

    NOKProduction Greenhorn

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #13
    Ok thanks, i setup xampp, trying it.
     
    NOKProduction, Jun 25, 2009 IP