Re: mod_rewrite and include paths

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, November 13, 2005 4:05 pm, Marcus Bointon wrote:
> This seems like a simple problem...

Maybe there should be a simple solution... :-)

> I have a rewrite like this:
>
> RewriteRule ^x/([0-9]+) x.php?x=$1 [PT,L]
>
> This maps a url like http://www.example.com/x/123 to http://
> www.example.com/x.php?x=123
>
> x.php contains a line to include some class like:
>
> require_once 'x.class.php';
>
> My include path contains '.' (plus paths to pear, etc), and the class
> file is in the top level directory.

If it's in the top level directory, then maybe that directory should
be hard-coded into the include_path, as well as '.'

include_path
".:/whatever/httpd.conf/has/for/DocumentRoot:/full/path/to/PEAR"

> So how can I get PHP to look in /? I can set include_path with a
> php_value in .htaccess, but I can only set it absolutely (losing
> existing values), not add to it (AFAIK?). I don't want to add an
> absolute path to my global include_path as there may be multiple
> independent deployments of the same scripts on the server, and I
> don't want them including each others files. Adding .. to the path
> would work but is a security risk. Any other ideas?

This all rules out the above, but one possibility is this:

In just the script that gives you trouble do this:

include_path("/full/path/to/DocumentRoot:" . include_path());
This may not be the right syntax/function to set include_path, but it
is a dynamic way to set the include path, from within PHP.

Of course, for the multiple deployments, you'll need to make the path
based on the deployment somehow.


Now, on to the simple solution I intimated at the beginning...

If mod_rewrite is giving you the headaches it gives me, just get rid
of it. :-)

INSTEAD, do this.

Create a PHP script, and name it 'x'

In .htaccess, force 'x' to be PHP as far as Apache is concerned:
<Files x>
  ForceType application/x-httpd-php
</Files>

You can now access your "x=123" from $_SERVER['PATHINFO'] (or is it
'PATH_INFO'?

No more endless tweaking of Regex rules in httpd.conf and logging the
mod_rewrite and dinking with ^/[0-9]+ junk and re-starting Apache
every time you want to try a change.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux