Results 1 to 4 of 4
  1. #1

    mod_rewrite... can't get my head around it

    At one point I knew this, but I haven't used it in a while.

    What code would I need for something simple, like rewriting

    http://www.whdsfsdgffdg.com/index.ph...t=whatever.php

    to

    http://www.whdsfsdgffdg.com/whatever

    or

    http://www.whdsfsdgffdg.com/whatever.html

    Thanks

  2. #2

    Re: mod_rewrite... can't get my head around it

    Originally posted by Jeanco
    At one point I knew this, but I haven't used it in a while.

    What code would I need for something simple, like rewriting

    http://www.whdsfsdgffdg.com/index.ph...t=whatever.php

    to

    http://www.whdsfsdgffdg.com/whatever

    or

    http://www.whdsfsdgffdg.com/whatever.html

    Thanks
    First off you need a .htaccess in your case it should be

    Code:
    RewriteEngine on
    RewriteBase /
    
    RewriteRule A_NAME/([^.]+)/ index.php?content=$1
    DirectoryIndex index.html index.php
    
    errorDocument 404 /index.php
    Making sure you change the A_NAME part

    Then save that file, reboot httpd for it to come into affect (linux only i think).

    Should work with direct new urls then.

    then your going to need this php snippet to get the new $_GET's out of the new urls

    PHP Code:
    //get full url -> extract "GET"-data
    $url $_SERVER['DOCUMENT_ROOT'] . strtolower($_SERVER['PHP_SELF']);
    $phpselfReg "({$_SERVER['SCRIPT_FILENAME']})(\/)?(.+)?";
    $getdata eregi_replace($phpselfReg"\\3"$url);  if($getdata != "") {          
          
    $get = array();
          
    $get explode("/"$getdata);
          if(
    count($get) > 0) {
          } else {
          }
    } else {
    }      

    // Use like so $something = $_GET[5] .. where 5 changes where the location is. to see the paths do a print_r($get); 
    Hope that helps!

    - Josh.
    <<Please see rules for signature setup>>

  3. #3
    Thanks, a few questions though. What am I supposed to be changing the A_NAME to? I want the page to change with each page, so if $content=whatever.php then it will show as whatever.html and if its $content=somethingelse.php then it will show as somethingelse.html

    Thanks Josh.

  4. #4
    You change A_NAME to what it will show up

    ex: http://domain.com/A_NAME/whatever
    ex: http://domain.com/A_NAME/somethingelse

    or you could delete A_NAME and just make it

    ex: http://domain.com/whatever (I believe, but i could be wrong.)


    Hope that helps again.

    - Josh.
    <<Please see rules for signature setup>>

Posting Permissions

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