Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Results 1 to 13 of 13

This is a discussion on RewriteRule in the Shared & Semi-Dedicated forum
Hello, I am trying to use $PATH_INFO to pass parameters to a script. I would like the url: http://domain.com/subdir/12/34 To redirect to url: http://domain.com/subdir/index.php/12/34 or ...

  1. #1
    JPC Addict
    Join Date
    Jul 2001
    Posts
    245

    RewriteRule

    Hello,

    I am trying to use $PATH_INFO to pass parameters to a script.

    I would like the url:
    http://domain.com/subdir/12/34

    To redirect to url:
    http://domain.com/subdir/index.php/12/34
    or
    http://domain.com/subdir/index.php&parmx=12&parmy=34

    I am struggling with the rewrite rule. I want to maintain the php file in the subdirectory subdir (and not in a lower level).

    Any ideas?

    Cheers,

    Gary

  2. #2
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    Instead of struggling with mod_rewrite, you can do this instead:

    In your .htaccess file add
    Code:
    <Files subdir>
      ForceType application/x-httpd-php
    </Files>
    Then create a file (not a directory) called "subdir" in your site's root. The Files directive above makes the server see this file as a PHP script, even though it has no extension.

    Somewhere near the top of your code, add the following:
    PHP Code:
        list($parmx$parmy) = explode('/'substr($_SERVER['PATH_INFO'], 1)); 
    This will split the PATH_INFO string into two variables, $parmx and $parmy that you can use in your code. Then just follow that code with the code from the index.php you were trying to put in the subdirectory.

    Hope this helps.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  3. #3
    Yeah, I know a LOT! Vin DSL's Avatar
    Join Date
    Mar 2003
    Location
    Arizona Uplands
    Posts
    10,775

    Re: RewriteRule

    Originally posted by gakenny
    ...I am struggling with the rewrite rule... Any ideas?
    Here you go. This is my gift to you for today. An explanation of how mod_rewrite works, from the guy who invented it:

    http://www.engelschall.com/pw/apache/rewriteguide/
    DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient.

    No Guts, No Story! VinDSL © 2010

  4. #4
    JPC Addict
    Join Date
    Jul 2001
    Posts
    245
    Hi Jason,

    Thanks - that does exactly what I was after. I had hoped to keep all of this in a subdirectory as indicated but I have wasted too much time on that option.

    Hi Vin,

    Thanks for the link. I struggled through that one before but I came up with a hurdle that I was unable to overcome.

    Thanks for the support, guys!

    Cheers,

    Gary

  5. #5
    JPC Guru Zhen-Xjell's Avatar
    Join Date
    Jan 2002
    Posts
    432

    Re: RewriteRule

    RewriteRule ^subdir/([0-9]+)/([0-9]+) subdir/index.php/$1/$2

    or

    RewriteRule ^subdir/([0-9]+)/([0-9]+) subdir/index.php&parmx=$1&parmy=$2
    Microsoft MVP Windows-Security 2005
    CastleCops | Cuddles 'n Kisses | Just a little poke | Zhen-Xjell

  6. #6
    JPC Addict
    Join Date
    Jul 2001
    Posts
    245
    Hi Jason,

    Your suggestion was good but I get a server error:
    [2003-08-13 22:39:41]: error: file has no execute permission: (/home/<account>/public_html/volunteers/view)

    Although the same works if the file is renamed view.php and the modified url keyed.

    Cheers,

    Gary

  7. #7
    JPC Addict
    Join Date
    Jul 2001
    Posts
    245
    Hi Zhen,

    This is similar to a solution that I tried. And I have now tried yours.

    Should this .htaccess be in the root of the site or in the subdirectory?

    The ^subdir/ statement (and specifically ^) denotes from the start. Is this from the start of the url, or the url for the current subdirectory?

    I currently get a page not found error when using a modification of your example (and no errors in the log!).

    Cheers,

    Gary
    Last edited by gakenny; 08-13-2003 at 05:15 PM.

  8. #8
    JPC Guru Zhen-Xjell's Avatar
    Join Date
    Jan 2002
    Posts
    432
    Vin or Zhen?
    Microsoft MVP Windows-Security 2005
    CastleCops | Cuddles 'n Kisses | Just a little poke | Zhen-Xjell

  9. #9
    JPC Addict
    Join Date
    Jul 2001
    Posts
    245
    Sorry Zhen! That was for you!

  10. #10
    JPC Guru Zhen-Xjell's Avatar
    Join Date
    Jan 2002
    Posts
    432
    The carrot denotes the start after the "domain.com/".

    Place it in the root folder, the parent to the subdir.
    Microsoft MVP Windows-Security 2005
    CastleCops | Cuddles 'n Kisses | Just a little poke | Zhen-Xjell

  11. #11
    JPC Addict
    Join Date
    Jul 2001
    Posts
    245
    Hi Zhen,

    This results in a Page Not Found error:
    RewriteRule ^view/([0-9]+)/([0-9]+) view/index.php/$1/$2

    Url http://domain.com/view/1/2

    .htaccess in root directory, index.php (that works!) in /view subdirectory.

    Cheers,

    Gary

  12. #12
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    Originally posted by gakenny
    Hi Jason,

    Your suggestion was good but I get a server error:
    [2003-08-13 22:39:41]: error: file has no execute permission: (/home/<account>/public_html/volunteers/view)

    Although the same works if the file is renamed view.php and the modified url keyed.

    Cheers,

    Gary
    Hmm...

    It worked fine for me. Since its PHP it shouldn't need execute permission, just read permission.

    Here's my example: http://www.interbrite.com/testme/1/2 (I'll leave it up for a couple days)

    What is the URL that you are using to access your script? Is it yourdomain.com/volunteeers/1/2 or it it yourdomain.com/volunteers/view/1/2? I'd suspect the latter, in which case make sure you have

    <Files volunteers/view>
    ForceType application/x-httpd-php
    </Files>

    in an .htaccess file in your public_html directory.

    If you are trying to use the former, you'll have problems because you can't have a file and a subdirectory with the same name in a directory. You'll either need to use a different name or try the rewrite method.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  13. #13
    JPC Addict
    Join Date
    Jul 2001
    Posts
    245
    Hi Jason,

    Well, the problem is now resolved. I am running this script on a non-Jag server and they are running php in a cgi environment.

    I have modified the .htaccess to read:
    <Files view>
    SetHandler application/x-httpd-php
    </Files>
    and this works a treat!

    I think I will tackle the ReWriteRule another day. I tried a lot of things with no luck.

    Thanks for the help guys.

    Cheers,

    Gary

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
  •