Simple mod rewrite issue, please help, my head is full

Discussion in 'Apache' started by Choller, Jun 23, 2007.

  1. #1
    I hope someone can help me.

    I have a simple mod rewrite issue but i can't get it to work.

    if someone goes here -> www.google.com/see/thispage

    I want to convert it to wwww.google.com/see/index.php?id=thispage so i can use some php to get the "thispage" variable.

    my index.php file is sitting in www.google.com/see (so it's NOT in the root dir).
     
    Choller, Jun 23, 2007 IP
  2. WebGeek182

    WebGeek182 Active Member

    Messages:
    510
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    95
    #2
    This one's not too hard. Put this in your .htaccess file and this should do it:

    
    RewriteEngine on
    RewriteRule ^see/(.*)$ /see/index.php?id=$1 [NC,L]
    
    Code (markup):
    If you need more help with .htaccess and mod_rewrite, here's a good .htaccess and mod_rewrite reference.
     
    WebGeek182, Jun 23, 2007 IP
  3. Choller

    Choller Peon

    Messages:
    388
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Weird i'm still getting a 404 error... dunno what could be wrong the code looks logical.
     
    Choller, Jun 23, 2007 IP
  4. WebGeek182

    WebGeek182 Active Member

    Messages:
    510
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    95
    #4
    2 questions:

    • Is "see" a subdomain? If you're using see.yourdomain.com, then the .htacess would need to be in the "see" folder.
    • If not a subdomain, what folder is your .htaccess in? That will affect your .htaccess commands.
     
    WebGeek182, Jun 23, 2007 IP
  5. Choller

    Choller Peon

    Messages:
    388
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    1. it's not a subdomain, its a regular folder.
    2. that is indeed a good one. the .htaccess was sitting in the /see folder, now i moved it to the root dir and i'm getting a 500 internal sever error.
     
    Choller, Jun 23, 2007 IP
  6. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #6
    Use ([^.]+).
     
    Nintendo, Jun 23, 2007 IP
    WebGeek182 likes this.
  7. Choller

    Choller Peon

    Messages:
    388
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks Nintendo that one does it but i'm almost there now.

    Now I get everything except the last character of the variable. For example www.google.com/see/thispage produces this wwww.google.com/see/index.php?id=thispag instead of this wwww.google.com/see/index.php?id=thispage

    I'm reading now on how i can get it all, hopefully i can figure it out.

    edit: got it --> ([^.*]+)
     
    Choller, Jun 24, 2007 IP
  8. WebGeek182

    WebGeek182 Active Member

    Messages:
    510
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    95
    #8
    Good catch, .htaccess man! :)
     
    WebGeek182, Jun 24, 2007 IP
  9. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #9
    (.*) is everything, so with

    RewriteRule ^see/(.*)$ /see/index.php?id=$1 [NC,L]

    even

    see/index.php?id=whatever

    whould make it go bonkers. To apache the original URL would also be a fake URL.
     
    Nintendo, Jun 25, 2007 IP