SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2002
    Location
    UK
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Search Engine-Friendly URLs

    Hi all, I'm trying to use Method 2 in the article http://www.sitepoint.com/print/485
    I'm trying to get the url /archive_b.php/1 from /archive_b.php?view=1

    I have in my .htaccess file
    RewriteEngine on
    RewriteBase /content/host/web/
    RewriteRule ^archive_b.php/([0-9]+)?$ /archive_b.php?view=$1 [T=application/x-httpd-php]
    and in my php file I have,
    PHP Code:
    header("HTTP/1.1 200 OK");

    $var_array explode("/",$REQUEST_URI); 

    function 
    count_all($arg
    {
    // skip if argument is empty
    if ($arg) {

    if(!
    is_array($arg))
     return 
    1;
     
    // else call recursively for all elements $arg
     
    foreach($arg as $key => $val)
     
    $count += count_all($val);
     return 
    $count
     }


    $num count_all($url_array);

    //add parm to a variable
    $view $var_array[1]; 
    I keep getting an error message - No input file specified
    The file reads /archive_b.php?view=1 and query's the database fine. Please could anyone help me as I can't figure out which part is going wrong?


    many thank's in advance!
    ch-boy

  2. #2
    SitePoint Wizard Mike Borozdin's Avatar
    Join Date
    Oct 2002
    Location
    Edinburgh, UK
    Posts
    1,743
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You seem to be mixing up mod_rewrite method and 404 method, get rid of that code, use _$GET["view"] to fetch data from the database.

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2002
    Location
    UK
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank's for the reply but I'm not sure that I understand your answer, I'm trying to get the var ?view=1 when I type
    /archive_b.php/1

    so instead I put ??

    PHP Code:
    $var_array explode("/",$REQUEST_URI);

    $view $_GET["view"]; 

  4. #4
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use $_GET['view'] to get your variable.

    BTW, this rewrite rule would IMHO make more sense
    Code:
    RewriteRule ^archive/([0-9]+)?$ /archive_b.php?view=$1 [T=application/x-httpd-php]
    giving you nice links like /archive/1

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2002
    Location
    UK
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've added this line but now get a 404 error instead
    Code:
    RewriteRule ^archive/([0-9]+)?$ /archive_b.php?view=$1 [T=application/x-httpd-php]

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2002
    Location
    UK
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've re-read the article http://www.sitepoint.com/print/485 and now if I'm on the right lines I re-name my file to article without the .php then in my .htaccess I add

    Code:
    <Files article>
     ForceType application/x-httpd-php
    </Files>
    my article php script has
    PHP Code:
    $var_array explode("/",$PATH_INFO);

    print_r ($_GET );

    $view $_GET["view"];
    $view2 $var_array[0]; 
    but when I goto /article/1 my browser isn't parsing the php file.

    I must be going mad!!
    Last edited by ch-boy; Jan 9, 2004 at 04:47.


Bookmarks

Posting Permissions

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